我是使用 Nethereum 的新手,我正在尝试调用owner()
BSC 智能合约中的一个函数,该函数返回所有者的地址。我的代码:
string url = String.Format("https://api.bscscan.com/api?module=contract&action=getabi&address={0}&apikey={1}", address, ApiKey);
var webRequest = WebRequest.Create(url) as HttpWebRequest;
if (webRequest == null)
{
return false;
}
webRequest.ContentType = "application/json";
webRequest.UserAgent = "Nothing";
using (var s = webRequest.GetResponse().GetResponseStream())
{
using (var sr = new StreamReader(s))
{
string contractABIstr = sr.ReadToEnd();
JObject contractABI = JObject.Parse(contractABIstr);
if (contractABI.SelectToken("status").ToString() == "0")
{
// Handle error...
}
string contractResults = (string)contractABI.SelectToken("result");
var web3 = new Web3();
var contract = web3.Eth.GetContract(contractResults, address);
Nethereum.Contracts.Function function = contract.GetFunction("owner");
string owner = function.GetData(); // <--- The result which is coming out wrong
}
}
我期望owner
成为一个钱包地址。但是,无论我使用什么合约地址,我的代码总是返回一个字符串"0x8da5cb5b"
(显然太短而不能成为地址),我注意到它恰好Sha3Signature
是function.FunctionBuilder.FunctionABI
. 有谁知道我在这里做错了什么?