Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix query balance of contract token #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

horan-geeker
Copy link

when I try use

client.EthCall(ethrpc.T{
            To:   contractAddress,
            Data: data,
        }, "latest")

to query balance of erc20 token

type T struct {
	From     string
	To       string
	Gas      int
	GasPrice *big.Int
	Value    *big.Int
	Data     string
	Nonce    int
}
func (t T) MarshalJSON() ([]byte, error) {
	params := map[string]interface{}{
		"from": t.From,
	}
	if t.To != "" {
		params["to"] = t.To
	}
	if t.Gas > 0 {
		params["gas"] = IntToHex(t.Gas)
	}
	if t.GasPrice != nil {
		params["gasPrice"] = BigToHex(*t.GasPrice)
	}
	if t.Value != nil {
		params["value"] = BigToHex(*t.Value)
	}
	if t.Data != "" {
		params["data"] = t.Data
	}
	if t.Nonce > 0 {
		params["nonce"] = IntToHex(t.Nonce)
	}

	return json.Marshal(params)
}

this let t.From = "" and get this json string {"id":1,"jsonrpc":"2.0","method":"eth_call","params":[{"data":"0x70a08231000000000000000000000000fe2e424e2ef9b929157dd525c414f4b128ee1bfb","from":"","to":"0xf4c90e18727c5c76499ea6369c856a6d61d3e92e"},"latest"]} after marshal

finnal error appear

invalid argument 0: hex string has length 0, want 40 for common.Address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant