tl;dr: I just wanted to reuse a "token currency type" with symbol and precisions validations out-of-the-box.

If I’m implementing “token” currency in my contracts, which one should I use?

I’m just asking that because looks like eosjs verifies get_currency_stats for asset and do not for extended_asset and I don’t need that verification. Actually it breaks my app because my contract has a completely different structure of the regular eosio.token...

Asset and Symbol default to eosio.token and both have precision. The asset has an additional amount.

Extended asset and symbol are the same except they both add a contract account. Any custom token will need the extended version.

Both extended and regular version will query get_currency_stats in order to find precision (cached in RAM). At present, it will try to verify precision because that is very important in how the transaction is encoded in binary and required when signing.

Apart from some helpful additives (max amount, precision, checks for valid symbols,...) it stores more than the asset class. It keeps the owner of the asset (given by an account). For EOS it is account eosio.token, which is the default account for the asset constructor. (Reference)

A list of some examples where arguments might be *optional* is given. The extended_asset can be constructed by either:

extended_asset(amount, *extended_symbol*) e.g. extended_asset(asset(150), extended symbol(S(4, EOS))

or

extended_asset(asset, *account*) e.g. extended_asset(asset(150)) for eosio.token

and we have

  • asset(amount, *symbol*) e.g. asset(150) for eosio.token

  • extended_symbol(symbol, *account*) e.g. extended_symbol(symbol, N(eosio.token))

  • symbol_type(symbol_name) e.g. construct with S(4, EOS)

  • S(P,X) a macro that takes precision and a string and converts it into a symbol

In total all 3 are neeeded: amount, symbol, account. Since your token is not owned by account eosio.token you should use extended_asset.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.