How do we accomplish this on EOSIO?

In Ethereum we get the reference of another contract using the contract address, what about for EOSIO?

Can anyone provide a sample code for this?

Would like to pull the balance from another smart contract.

2 Answers 2


Declare the following struct in your contract

struct account {
        asset    balance;
        uint64_t primary_key()const { return balance.symbol.name(); }

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

Write the following in one of the action of contract. It is reading the accounts table of eosio.token contract and printing the balance of "user111"

symbol_type symbol(S(4,SYS));
accounts fromAcc(N(eosio.token),N(user111));
const auto& myAcc = fromAcc.get(symbol.name());
  • thanks for the information, I also assume that the contract file of eosio.token.hpp should be included in the contract where I'm calling it right?
    – Dominic
    Jul 10, 2018 at 0:41
  • You can use it without including eosio.token.hpp, In that case you have to copy "struct account" and its multi_index table type as shown in the above answer to your contract file Jul 10, 2018 at 11:04
  • So if you #include <eosiolib/eosio.token.hpp> you can just use that last section of your post, without struct account... and typedef eosio::multi_index...? Cheers, good answer
    – Alex
    Jul 22, 2018 at 17:38
  • When I try this, I get the error: unable to find key Aug 26, 2018 at 18:53

By querying eosio.token's accounts table.

./cleos/cleos -u http://api.eosnewyork.io:80 get table eosio.token <account-name> accounts

BTW, this returns [] if the account is never transferred any token (like EOS).

Use userres table to get account info.

./cleos/cleos -u http://api.eosnewyork.io:80 get table eosio <account-name> userres

  • Yeah, but how do we translate it or write it inside of another smart contract? Any idea?
    – Dominic
    Jul 9, 2018 at 5:14
  • @Dominic I don't know how to access table data of other contracts from one contract. But a workaround could be moving this logic from contract to app. In other word, contract logic only does simple work.
    – eval
    Jul 9, 2018 at 19:47
  • Unfortunately, the logic requires to get the balance directly from another contract.
    – Dominic
    Jul 10, 2018 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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