2

If I have a contract like below:

contract wallet{

   mapping (address => uint) balances
   function send(){...}
   ......

}

and I deploy this contract on the ethereum.

When I want to query the balances for example check the balance of Alice, is there any api to do this query directly like SQL.

1

There is no query api like SQL, you can invoke contract method to finish it. This is a simple contract, you can get balance by name

pragma solidity ^0.4.0;

contract Wallet {

    mapping (address => uint) balance;

    function desosite() payable{
        balance[msg.sender] += msg.value;
    }

    function getBlance() constant returns (uint) {
        return balance[msg.sender];
    }


}

Hope it helps~

| improve this answer | |
  • Can I call the "getbalance()" to get data outside the etherum? Or it can only be called by another contract? – njuyuanrui Aug 9 '17 at 1:33
  • If you had deployed this contract on private chain, call your_contract_name.getBalance(from:eth.coinbase) – BinGoBinBin Aug 9 '17 at 1:37

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.