3

How can I get accounts info in a smart contract? Or if given a public key and account_name, is there any way can verify that account has this public key in a certain permission?

  • 1
    I also have the same question. Have you solved this? How to know a public key and account is associated in the contract? – BruceLingKing Sep 22 '18 at 3:40
  • 1
    Its important to get available cpu in a smart contract. What is the recommended way for this? I cannot find any function like get_account_info on contract level (NOT cleos!). – Sven Motonaka Nov 19 '18 at 7:39
1

You can retrieve information about an account that is involved in a contract by querying the contract's table with the get table command.


You can also use get account which reveals the associated permission levels and public keys.

Example from docs:

$ cleos get account eosio --json
{
  "account_name": "eosio",
  "privileged": true,
  "last_code_update": "2018-05-23T18:00:25.500",
  "created": "2018-03-02T12:00:00.000",
  "ram_quota": -1,
  "net_weight": -1,
  "cpu_weight": -1,
  "net_limit": {
    "used": -1,
    "available": -1,
    "max": -1
  },
  "cpu_limit": {
    "used": -1,
    "available": -1,
    "max": -1
  },
  "ram_usage": 1279625,
  "permissions": [{
      "perm_name": "active",
      "parent": "owner",
      "required_auth": {
        "threshold": 1,
        "keys": [{
            "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
            "weight": 1
          }
        ],
        "accounts": [],
        "waits": []
      }
    },{
      "perm_name": "owner",
      "parent": "",
      "required_auth": {
        "threshold": 1,
        "keys": [{
            "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
            "weight": 1
          }
        ],
        "accounts": [],
        "waits": []
      }
    }
  ],
  "total_resources": null,
  "delegated_bandwidth": null,
  "voter_info": {
    "owner": "eosio",
    "proxy": "",
    "producers": [],
    "staked": 0,
    "last_vote_weight": "0.00000000000000000",
    "proxied_vote_weight": "0.00000000000000000",
    "is_proxy": 0,
    "deferred_trx_id": 0,
    "last_unstake_time": "1970-01-01T00:00:00",
    "unstaking": "0.0000 SYS"
  }
}
  • 1
    But how to "get account" in a smart contract? I would like to get an account info in a smart contract. – Alvin Sun Jul 26 '18 at 6:03
  • I'm not sure what you're asking. In EOS you only need 1 account for all EOS applications, so you would query that account for its associated permission levels and public keys like you asked in your post. To obtain the specific attributes of that account name in the contract, you would query the table to see what the value of the variables are for that account. It wouldn't make sense to make a new account specific to the dapp because that would cost too much for the dapp creator as well as the end user ultimately if they were to cover that cost. – Nat Jul 26 '18 at 10:25
  • thanks for your comments. Sorry about that I did not make the question clear. I actually would like to implement a function in a smart contract eg: verify(account_name user, public_key pubKey); In this function, it is able to check whether the pubkey is associated with that given user. This sample function is useless because I cannot disclose my business logic too much, but it is actually a core part I need to achieve in my project. Thanks – Alvin Sun Jul 26 '18 at 14:11
  • Ah I see now. I do not see a specific example, but I believe you can find the logic you are looking to implement in eosjs: developers.eos.io/eosjs/reference#getaccount – Nat Jul 26 '18 at 16:18
  • In ethereum we get the account like const accounts = await web3.eth.getAccounts(); in case we are using javascriptvm in redix but on test net like rinkbey we can only have one account. As @Nat said we need only one account of all EOS applications. As I get what you want , you could first send a simple transaction to that account and use eosio:assert to handle condition. – Nirdesh Kumar Choudhary Sep 22 '18 at 5:39

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.