async void Start() { /* * // SPDX-License-Identifier: MIT * pragma solidity ^0.8.0; * * contract AddTotal { * uint256 public myTotal = 0; * * function addTotal(uint8 _myArg) public { * myTotal = myTotal + _myArg; * } * } */ // set chain: ethereum, moonbeam, polygon etc string chain = "ethereum"; // set network mainnet, testnet string network = "rinkeby"; // smart contract method to call string method = "myTotal"; // abi in json format string abi = "[ { \"inputs\": [ { \"internalType\": \"uint8\", \"name\": \"_myArg\", \"type\": \"uint8\" } ], \"name\": \"addTotal\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\" }, { \"inputs\": [], \"name\": \"myTotal\", \"outputs\": [ { \"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\" } ], \"stateMutability\": \"view\", \"type\": \"function\" } ]"; // address of contract string contract = "0x7286Cf0F6E80014ea75Dbc25F545A3be90F4904F"; // array of arguments for contract string args = "[]"; // connects to user's browser wallet to call a transaction string response = await EVM.Call(chain, network, contract, abi, method, args); // display response in game print(response); }
public static async Task <string> URI(string _chain, string _network, string _contract, string _tokenId, string _rpc = "") { string method = "tokenURI"; string[] obj = { _tokenId }; string args = JsonConvert.SerializeObject(obj); string response = await EVM.Call(_chain, _network, _contract, abi, method, args, _rpc); return(response); }
public static async Task <int> BalanceOf(string _chain, string _network, string _contract, string _account, string _rpc = "") { string method = "balanceOf"; string[] obj = { _account }; string args = JsonConvert.SerializeObject(obj); string response = await EVM.Call(_chain, _network, _contract, abi, method, args, _rpc); try { return(int.Parse(response)); } catch { Debug.LogError(response); throw; } }
public static async Task <BigInteger> TotalSupply(string _chain, string _network, string _contract, string _rpc = "") { string method = "totalSupply"; string[] obj = {}; string args = JsonConvert.SerializeObject(obj); string response = await EVM.Call(_chain, _network, _contract, abi, method, args, _rpc); try { return(BigInteger.Parse(response)); } catch { Debug.LogError(response); throw; } }
public static async Task <List <BigInteger> > BalanceOfBatch(string _chain, string _network, string _contract, string[] _accounts, string[] _tokenIds, string _rpc = "") { string method = "balanceOfBatch"; string[][] obj = { _accounts, _tokenIds }; string args = JsonConvert.SerializeObject(obj); string response = await EVM.Call(_chain, _network, _contract, abi, method, args, _rpc); try { string[] responses = JsonConvert.DeserializeObject <string[]>(response); List <BigInteger> balances = new List <BigInteger>(); for (int i = 0; i < responses.Length; i++) { balances.Add(BigInteger.Parse(responses[i])); } return(balances); } catch { Debug.LogError(response); throw; } }