unity调用智能合约时出错

问题描述 投票:0回答:0

我试图在我的 solidity 代码中调用函数

muck()

function muck() public returns (uint256 alsomuck){
        alsomuck = 1;
    }

我在 Unity 中通过这段代码调用它:

    private async void Start()
    {
        var web3 = new Web3("https://rpc-mumbai.matic.today");

        string contractAbi = @"[
          {
            ""constant"": false,
            ""inputs"": [],
            ""name"": ""muck"",
            ""outputs"": [
              {
                ""name"": ""alsomuck"",
                ""type"": ""uint256""
              }
            ],
            ""payable"": false,
            ""stateMutability"": ""nonpayable"",
            ""type"": ""function""
          }
        ]";

        var contractAddress = contractAddress;
        var contract = web3.Eth.GetContract(contractAbi, contractAddress);

        var function = contract.GetFunction("muck");
        var result = await function.CallAsync<string>();

        Debug.Log("Result: " + result);
    }

但我在控制台中收到此错误:

HttpRequestException: 403 (Forbidden)
System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode () (at <853a2350e6f2416eb8e7fe05624a86b6>:0)
Nethereum.JsonRpc.Client.RpcClient.SendAsync (Nethereum.JsonRpc.Client.RpcMessages.RpcRequestMessage request, System.String route) (at <eb3f05c7031b4ce1b15247513c04d8c1>:0)

似乎由于某种原因我没有访问孟买网络的权限

我尝试仔细检查合约地址和孟买 RPC 地址,但我仍然得到这个错误

c# unity3d blockchain solidity binance
© www.soinside.com 2019 - 2024. All rights reserved.