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; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var ConnString = "Server=tcp:" + serverName + ",1433;Initial Catalog = user_registry; Persist Security Info=False;User ID = Jepidoptera; Password="******"secrets").GetSection("databasePassword").Value + "; MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout = 30;"; services.AddTransient <IQueryPipe>(_ => new QueryPipe(new SqlConnection(ConnString))); services.AddTransient <ICommand>(_ => new Command(new SqlConnection(ConnString))); // Add framework services. services.AddMvc(); // services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod())); // add configuration service services.AddSingleton <IConfiguration>(Configuration); // start up SecretsController class var secrets = new SecretsController(Configuration); }
private void Start() { Instance = this; }