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.

eth
  • 85,679
  • 53
  • 285
  • 406
njuyuanrui
  • 81
  • 4
  • Related https://ethereum.stackexchange.com/questions/1983/web3-eth-getstorageat-for-mapping and [tag:get-storage-at] – eth Aug 08 '17 at 15:56

1 Answers1

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~

BinGoBinBin
  • 2,161
  • 13
  • 17