Example #1
0
    public static async Task <List <string> > OwnerOfBatch(string _chain, string _network, string _contract, string[] _tokenIds, string _multicall = "", string _rpc = "")
    {
        string method = "ownerOf";

        // build array of args
        string[][] obj = new string[_tokenIds.Length][];
        for (int i = 0; i < _tokenIds.Length; i++)
        {
            obj[i] = new string[1] {
                _tokenIds[i]
            };
        }
        ;
        string args     = JsonConvert.SerializeObject(obj);
        string response = await EVM.MultiCall(_chain, _network, _contract, abi, method, args, _multicall, _rpc);

        try
        {
            string[]      responses = JsonConvert.DeserializeObject <string[]>(response);
            List <string> owners    = new List <string>();
            for (int i = 0; i < responses.Length; i++)
            {
                // clean up address
                string address = "0x" + responses[i].Substring(responses[i].Length - 40);
                owners.Add(address);
            }
            return(owners);
        }
        catch
        {
            Debug.LogError(response);
            throw;
        }
    }
Example #2
0
    static void Main()
    {
        var evm = new EVM();

        evm.SetValue("print", new Action <object>(Console.WriteLine));
        const string script = @"
function calc() {
	print(2 + 3)
	print(2 - 3)
	print(2 * 3)
	print(2 / 3)
}
function ctrl() {
	n = 1
	if (n > 0) {
		print(""n > 0"")
	} else {
		print(""n < 0"")
	}
	arr = [1,2,3]
	for (i = 0, arr.count) {
		print(arr[i])
	}
	foreach (i in arr) {
		print(i)
	}
	t = {a:1, b:2}
	foreach (o in t) {
		print(o)
	}
	print(t[""a""])
	print(t.b)
}
function closure() {
	n = 100
	f = function() {
		n = n + 1
		return n
	}
	for (i = 0, 10)  {
		print(f())
	}
	f2 = function(m) {
		return f() + m
	}
	for (i = 0, 10)  {
		print(f2(100))
	}
}
function main() {
	print(""hello world!"")
	calc()
	ctrl()
	closure()
}
main()
";

        evm.Execute(script);
    }
Example #3
0
    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);
    }
Example #4
0
    async void Start()
    {
        string chain       = "ethereum";
        string network     = "mainnet"; // mainnet ropsten kovan rinkeby goerli
        int    blockNumber = await EVM.BlockNumber(chain, network);

        print(blockNumber);
    }
Example #5
0
    async void Start()
    {
        string message   = "YOUR_MESSAGE";
        string signature = "0x94bdbebbd0180195b89721a55c3a436a194358c9b3c4eafd22484085563ff55e49a4552904266a5b56662b280757f6aad3b2ab91509daceef4e5b3016afd34781b";

        string address = await EVM.Verify(message, signature);

        print(address);
    }
Example #6
0
    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);
    }
Example #7
0
    async void Start()
    {
        string chain   = "ethereum";
        string network = "rinkeby"; // mainnet ropsten kovan rinkeby goerli
        string account = "0x2aF598ed8104483776661643BCD4995036205760";

        string balance = await EVM.BalanceOf(chain, network, account);

        balanceTxt.text = balance;
    }
Example #8
0
    async void Start()
    {
        string chain   = "ethereum";
        string network = "rinkeby";
        string account = "0xdD4c825203f97984e7867F11eeCc813A036089D1";

        string nonce = await EVM.Nonce(chain, network, account);

        print(nonce);
    }
Example #9
0
    async void Start()
    {
        string chain       = "ethereum";
        string network     = "mainnet";
        string transaction = "0x911d4ec9193e0dc14d9d034d88c311453112c5097f29c366ccc9c5e5bc7072e1";

        string txStatus = await EVM.TxStatus(chain, network, transaction);

        print(txStatus); // success, fail, pending
    }
Example #10
0
    async void Start()
    {
        string chain   = "rootstock";
        string network = "testnet";
        string account = "0xdD4c825203f97984e7867F11eeCc813A036089D1";
        string rpc     = "https://public-node.testnet.rsk.co";

        string balance = await EVM.BalanceOf(chain, network, account, rpc);

        print(balance);
    }
Example #11
0
    async void Start()
    {
        string method = "addTotal";
        // 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\" } ]";
        // array of arguments for contract
        string args = "[\"1\"]";

        string contractData = await EVM.CreateContractData(abi, method, args);

        print(contractData);
    }
Example #12
0
    static void Main(string[] args)
    {
        var evm = new EVM();

        evm.SetValue("print", new Action <object>(Console.WriteLine));
        const string script = @"
func calc() {
	print(2 + 3)
	print(2 - 3)
	print(2 * 3)
	print(2 / 3)
}
func ctrl() {
	n = 1
	if (n > 0) {
		print(""n > 0"")
	} else {
		print(""n < 0"")
	}
	arr = [1,2,3]
	for (i = 0, arr.count) {
		print(arr[i])
	}
	foreach (i in arr) {
		print(i)
	}
}
func closure() {
	n = 100
	f = func() {
		n = n + 1
		return n
	}
	for (i = 0, 10)  {
		print(f())
	}
}
func main() {
	print(""hello world!"")
	calc()
	ctrl()
	closure()
}
main()
";

        evm.Execute(script);
    }
Example #13
0
    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;
        }
    }
Example #14
0
    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;
        }
    }
Example #15
0
    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;
        }
    }