// GetBalance makes an RPC call to get the balance of an address.
// Returns the balance in ether, and if a token has been specified, it returns the balance of the token too using the ERC20 function balanceOf(address).
// To check balance (ether):
//  curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x357dd3856d856197c1a000bbAb4aBCB97Dfc92c4","latest"],"id":1}' http://localhost:8545
// To check balance (ERC20):
//  curl -X POST --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"data":"0x70a08231000000000000000000000000cba75F167B03e34B8a572c50273C082401b073Ed","to":"0xa34de7bd2b4270c0b12d5fd7a0c219a4d68d732f"},"latest"],"id":1}' http://localhost:8545
GetBalance makes an RPC call to get the balance of an address.
Returns the balance in ether, and if a token has been specified, it returns the balance of the token too using the ERC20 function balanceOf(address).
// GetBalance makes an RPC call to get the balance of an address . // Returns the balance in ether and if a token has been specified it returns the balance of the token too using the ERC20 function balanceOf ( address ) . // To check balance ( ether ) : // curl - X POST -- data ' { " jsonrpc " : " 2 . 0 " " method " : " eth_getBalance " " params " : [ " 0x357dd3856d856197c1a000bbAb4aBCB97Dfc92c4 " " latest " ] " id " : 1 } ' http : // localhost : 8545 // To check balance ( ERC20 ) : // curl - X POST -- data ' { " jsonrpc " : " 2 . 0 " " method " : " eth_call " " params " : [ { " data " : " 0x70a08231000000000000000000000000cba75F167B03e34B8a572c50273C082401b073Ed " " to " : " 0xa34de7bd2b4270c0b12d5fd7a0c219a4d68d732f " } " latest " ] " id " : 1 } ' http : // localhost : 8545
func (c *EthCli) GetBalance(address, token string, ethBal, tokBal *big.Int) (err error) {
	var response interface{}
	var ok bool
	if err = c.Call("eth_getBalance", []interface{}{address, "latest"}, &response); err != nil {
		return
	}
	if ethBal, ok = ethBal.SetString(response.(string), 0); !ok {
		err = ErrBadAmt
	}
	if token != "" {
		var data string
		data = "0x70a08231" + "000000000000000000000000" + address[2:] 
		if err = c.Call("eth_call", []interface{}{map[string]interface{}{"to": token, "data": data}, "latest"}, &response); err != nil {
			return
		}
		if tokBal, ok = tokBal.SetString(response.(string), 0); !ok {
			err = ErrBadAmt
		}
	}
	return
}
func ( c * EthCli ) GetBalance ( address , token string , ethBal , tokBal * big . Int ) ( err error ) { var response interface { } var ok bool if err = c . Call ( " " , [ ] interface { } { address , " " } , & response ) ; err != nil { return } if ethBal , ok = ethBal . SetString ( response . ( string ) , 0 ) ; ! ok { err = ErrBadAmt } if token != " " { var data string data = " " + " " + address [ 2 : ] if err = c . Call ( " " , [ ] interface { } { map [ string ] interface { } { " " : token , " " : data } , " " } , & response ) ; err != nil { return } if tokBal , ok = tokBal . SetString ( response . ( string ) , 0 ) ; ! ok { err = ErrBadAmt } } return }
GetBalance makes an RPC call to get the balance of an address.
GetBalance makes an RPC call to get the balance of an address .
// get ether // get token // balanceOf(address) + 12 zeroes padded + address