我想使用 Multicall 进行批量调用,但我不明白为什么我不断收到错误。已经被困在这里有一段时间了。有问题的合约将 u256 作为其唯一参数,并返回一个地址数组。该合约位于 Polygon,我 100% 确定我在正确的链上使用正确的 HTTP 提供程序/端点。我已经多次将此函数称为单调用,但由于某种原因多重调用无法工作,我担心它可能与多调用内部结构有关。
我输入的ABI是我要调用的合约的ABI,应该是正确的。
ContractError(
Revert(
Bytes(0x),
),
),
当我更改函数名称时,我得到:
DecodingError(
InvalidData,
),
)
Error fetching data: Invalid data
我不知道这里出了什么问题,我确信我有正确的 ABI。这是完整的功能:
pub async fn get_pair_traders_array_two(chain: &str) -> Result<Vec<Result<Token, Bytes>>, Box<dyn std::error::Error>> {
let multicall_address = "0x11ce4B23bD875D7F5C6a31084f55fDe1e9A87507".parse::<Address>()?;
let contract_address = "CONTRACT_ADDRESS".parse::<Address>()?;
// Retrieve the endpoint from the NODE_ENDPOINTS_MAP
let endpoint = match NODE_ENDPOINTS_MAP.get(chain) {
Some(url) => url,
None => return Err(Box::try_from(anyhow!("Unsupported chain")).unwrap()),
};
// (ugly way to write the ABI inline, you can otherwise read it from a file)
let abi: Abi = serde_json::from_str(r#"[{"removed too long"}]";
// connect to the network
let client = Provider::<Http>::try_from("NODE_ENDPOINT")?;
// create the contract object. This will be used to construct the calls for multicall
let client = Arc::new(client);
let contract = Contract::<Provider<Http>>::new(contract_address, abi, client.clone());
// Create a new Multicall instance with the specified version
let mut multicall = Multicall::new(client.clone(), Some(multicall_address)).await?;
// Create a single call
let argument = U256::from(0);
let call = contract.method::<_, Vec<Address>>("symbolArray", argument)?;
// Add the call to the multicall
multicall.add_call(call, false);
// Call the multicall and get the result
let result = multicall.call().await?;
Ok(result)
}
当我使用 Polygonscan 时,我只需输入 0 即可检索 H160:地址类型的数组。互联网上的资源很少,并且 ethers-rs 的文档状态很差。如果有人知道我的问题的解决方案,请在这里帮助我!
事实证明 MulticallV1 不受支持,或者至少对我来说对 ethers-rs 不起作用。一旦我使用 MulticallV3,我的代码就立即开始工作。