tomusdrw / rust-web3

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth
MIT License
1.45k stars 465 forks source link

How to read a public variable of a contract? #611

Open hzqd opened 2 years ago

hzqd commented 2 years ago

I code:

web3::contract::Contract::from_json(...).call(...).await?;

The problem is the call method returns a H256, how should I read the data of contract variables and functions execution results?

elpiel commented 2 years ago

You don't need to use call but query instead:

https://github.com/AmbireTech/adex-validator-stack-rust/blob/f4fb43b3c6c8765be7a7c68345379b72ad8cea01/adapter/src/ethereum/client.rs#L253-L265