6

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?

5
  • 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? Commented May 30, 2018 at 0:03
  • Yes! I want to get the balance of my contract account inside the contract!
    – yang24201
    Commented May 31, 2018 at 5:14
  • Can you throw up the whole project/contract on a GitHub repo? I'll take a look. Commented Jun 1, 2018 at 1:02
  • I am not sure, but this might help: github.com/EOSIO/eos/issues/638 Commented Jun 14, 2018 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
    Commented Feb 18, 2019 at 10:34

1 Answer 1

2

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.

0

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