3

I want to execute get_supply from currency.hpp.

Here is the definition:

asset get_supply( symbol_name symbol )const {
        accounts t( _contract, symbol );
        return t.get(symbol).balance;
     }

Currency constructor:

currency( account_name contract )
         :_contract(contract)
         { }

I am trying like that:

void get_supply(extended_asset mytoken) {
        extended_symbol es = mytoken.get_extended_symbol();
        auto sym = es.symbol;
        auto curr = currency(N(mytoken.token));
        auto stats = curr.get_supply(sym);
    }

mytoken.token -> custom token contract (copy of eosio.token)

I am getting error:

Error 3050003: eosio_assert_message assertion failure Error Details: assertion failure with message: unable to find key

Anyone knows how to use this function correctly?

0

The problem occurs on the line:

return t.get(symbol).balance;

The reason is that the primary key in the multi-index table does not exist. This means that you must have not added the symbol to the accounts table. You would have to do this by using the multi_index::emplace function before trying to access the table entry.

Presumably it could also be that the values you are using for the contract and scope of the table are incorrect.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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