I am using Nethereum to call a smart contract function in Ropsten. I am also using Infura.
The function required the contract owner's permission to execute. This is my code:
var account = new Account(ownerPrivateKey)
var web3 = new Web3(account, $"https://ropsten.infura.io/v3/{infuraId}");
var contract = web3.Eth.GetContract(abi, contractAddress);
var function = contract.GetFunction("myFunction");
var result = await function .CallAsync<dynamic>(address, true);
I got error: Nethereum.JsonRpc.Client.RpcResponseException: execution reverted: Ownable: caller is not the owner. I think I need to sign the transaction before sending it but I don't know how. I don't know whether I should use CallAsync or SendTransactionAsync because the function writes data down, not reading anything. I tried SendTransactionAsync but it doesn't seem to work with Infura. Anyone have experience with this, please help me. I am new to this.
My contract function:
function myFunction(address account, bool flag) internal {
_address[account] = flag;
}
$"https://ropsten.infura.io/v3/{infuraId}"
?execution reverted: Ownable: caller is not the owner
implies that this is not the problem. Sounds like you can fix this error be changing the value ofownerPrivateKey
to be that of the account used for deploying this contract.