public static void ArbitraryFunction(string command = "") { privatekey = SecretsController.SecretKey("privatekey"); // account 2 // privatekey = "95d16070fca17cb283db778650817b58b42c3ce8c164cd038037ba77bbad80f7"; tokenAddress = SecretsController.SecretKey("address"); abi = SecretsController.SecretKey("abi"); url = SecretsController.SecretKey("infura_url"); account = new Account(privatekey); web3 = new Web3(account, url); Contract goTokenContract = web3.Eth.GetContract(abi, tokenAddress); // parse function and parameters int paramStart = command.IndexOf('('); string function = command.Substring(0, command.IndexOf('(')); string[] parameters = command.Substring(paramStart).Trim(new char[2] { '(', ')' }).Split(','); // convert to appropriate data types for (int i = 0; i < parameters.Length; i++) { if ((string)parameters[i] != "") { parameters[i] = parameters[i].Trim(new char[2] { '"', ' ' }); } else { break; } } try { if (parameters.Length == 1 && (string)parameters[0] == "") { parameters = null; } Task <BigInteger> ff = goTokenContract.GetFunction(function).CallAsync <BigInteger>(account.Address, gas: new HexBigInteger(60000), value: new HexBigInteger(0), functionInput: parameters); Console.WriteLine(ff.Result); } catch (Exception e) { Console.WriteLine(e.Message); } }
private static void Initialize() { // set up magic numbers tokenAddress = SecretsController.SecretKey("address"); abi = SecretsController.SecretKey("abi"); url = SecretsController.SecretKey("infura_url"); // account 1 privatekey = SecretsController.SecretKey("privatekey"); // account 2 // privatekey = "95d16070fca17cb283db778650817b58b42c3ce8c164cd038037ba77bbad80f7"; account = new Account(privatekey); web3 = new Web3(account, url); goToken = new StandardTokenService(web3, tokenAddress); init = true; }