I am using Nethereum to call a function called
owner()
in a BSC contract, which should return the contract owner's address, however when I use the
CallAsync()
method, I get an exception "No connection could be made because the target machine actively refused it"
My code (simplified):
using (var s = webRequest.GetResponse().GetResponseStream())
{
using (var sr = new StreamReader(s))
{
string contractABIstr = sr.ReadToEnd();
JObject contractABI = JObject.Parse(contractABIstr);
string contractResults = (string)contractABI.SelectToken("result");
var web3 = new Web3();
var contract = web3.Eth.GetContract(contractResults, address);
Nethereum.Contracts.Function = contract.GetFunction("owner");
string owner = "";
Task<string> task = function.CallAsync<string>();
owner = await task;
}
}
When calling the line
owner = await task
, I get an exception with message "Error occurred when trying to send rpc requests(s)", which has an inner exception with the message "An error occurred while sending the request.", which has its own inner exception with the message "Unable to connect to the remote server", and this one has its own inner exception saying "No connection could be made because the target machine actively refused it [IP address]"
Does anyone know what I'm doing wrong here? (I've simplified the code above but I do check that the function exists)
What I have tried:
Changing configuration from 127.0.0.1, but not sure how to do this as there is no web.config file.