I have copy the account struct from the smart contract eosio.token into my own contract and typedef multi_index like this:
//@abi table accounts i64 struct account { asset balance; uint64_t primary_key() const { return balance.symbol.name(); } };

typedef eosio::multi_index<N(accounts), account> accounts;

And I define a accounts type variable named accountstable which code is N(eosio.token) and scope is _self. Code is here:

accounts accountstable(N(eosio.token), _self); const auto &ac = accountstable.get(CORE_SYMBOL); return ac.balance;

But this doesn't work for me and get the error message means can not find the key. Something wrong?

  • So you're trying to determine the balance of an account inside the contract itself? You're not querying the balance of a user externally? – John Williamson May 30 '18 at 0:03
  • Yes! I want to get the balance of my contract account inside the contract! – yang24201 May 31 '18 at 5:14
  • Can you throw up the whole project/contract on a GitHub repo? I'll take a look. – John Williamson Jun 1 '18 at 1:02
  • I am not sure, but this might help: github.com/EOSIO/eos/issues/638 – Allen Fernandes Jun 14 '18 at 8:48
  • If you're using eosio.cdt >= 1.3.0, I answered a very similar question here: eosio.stackexchange.com/a/3958/2944. – Vlad Feb 18 '19 at 10:34

Use this:

symbol_type symbol(S(4,SYS)); const auto& ac = accountstable.get(symbol.name());

You cannot .get(CORE_SYMBOL) for some reason. I dunno. This had me stumped for hours.


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