web3 :: contract :: Contract :: query的“params”参数应该是什么样的?

时间:2018-03-31 13:39:30

标签: rust ethereum smartcontracts

我正在尝试与multisig智能合约(Gnosis multisig)进行互动,并询问交易详情和确认数量。

以下是我想要做的简单的Python代码:

import json
from web3 import Web3, HTTPProvider, IPCProvider

contractAddress = '0x...'

web3 = Web3(HTTPProvider('https://mainnet.infura.io'))

with open('contract.abi', 'r') as abi_definition:
    abi = json.load(abi_definition)

contract = web3.eth.contract(contractAddress, abi=abi)
tx = contract.call().transactions(123)
confirmations = contract.call().getConfirmations(123)

print(tx)
print(confirmations)

这是我到目前为止提出的Rust代码:

extern crate web3;

use web3::contract::{Contract, Options};
use web3::types::Address;

fn main() {
    let (_eloop, http) = web3::transports::Http::new("https://mainnet.infura.io").unwrap();
    let web3 = web3::Web3::new(http);

    // The contract address.
    let address: Address = "0x...".parse().unwrap();

    // Access the contract
    let contract = Contract::from_json(web3.eth(), address, include_bytes!("./abi.json")).unwrap();

    // Query the contract instance
    // And this is where I'm stuck!
    let result = contract.query("transactions...");
}

documentation that I found没有解释什么是“params”以及它们应该如何传递给函数。

2 个答案:

答案 0 :(得分:0)

答案在于Tokenize特征,该特征是针对Tokenizable s的vecs,数组或元组实现的,而另一特征又是针对例如String实现的。 u64bool&str

因此,如果您有.to_string(),只需在其上调用String即可获得.try_into::<u64>()。或者,如果您有一个号码,("transactions".to_string(), 123u64)。或者也许是它的组合,例如params

我怎么知道? P类型为Tokenize,它是通用的并受where P: Tokenize约束(请参阅RewriteEngine On RewriteCond %{REQUEST_URI} ^[^_]+$ [NC] RewriteRule . /my-particular-page.php [L] ?)。

答案 1 :(得分:0)

文档未解释什么是“参数”的原因是,您可以传递在智能合约本身中公开定义和可访问的任何函数名称。

balanceOf是任何ERC-20令牌的默认功能,通常以它为例。

您必须检查用于该调用的Python库中调用了哪个函数:contract.call().transactions(123)。您需要该函数的确切名称才能在web3-rust Query()中进行调用。

如果您还没有看到Github web3-rust examples,也许也值得一看。