我想使用C#调用一个契约函数。
这是以太扫描的合同(https://etherscan.io/token/0x8c9b261faef3b3c2e64ab5e58e04615f8c788099#readContract)
我想称函数24为"getCollectibleDetails“。
这是我到目前为止所做的代码,但它不起作用。
var web3 = new Web3("https://mainnet.infura.io");
var contract = web3.Eth.GetContract(abi, contractAddress);
var function = contract.GetFunction("getCollectibleDetails");
var parameters = new object[]
{
new
{
Data = 157517,
To = "0x8c9b261faef3b3c2e64ab5e58e04615f8c788099"
}
};
var result = function.GetData(parameters);有人遇到过这种情况吗?
提前感谢您的帮助。
发布于 2019-06-19 16:40:52
这三行是对的
var web3 = new Web3("https://mainnet.infura.io");
var contract = web3.Eth.GetContract(abi, contractAddress);
var function = contract.GetFunction("getCollectibleDetails");我明白你在这里想做什么,但有一个更好的方法可以做到这一点:
var parameters = new object[]
{
new
{
Data = 157517,
To = "0x8c9b261faef3b3c2e64ab5e58e04615f8c788099"
}
};让我们假设getCollectibleDetails函数接受一个参数"address“并返回一个字符串作为响应:
// Define the address
string address = "0xb621...";
// Create an array of objects for the param
object[] params = new object[1]{ address };
// Call the function and pass in the params
var result = function.CallAsync<string>(params);https://ethereum.stackexchange.com/questions/69040
复制相似问题