public Web3Service(Web3ConnectionOptions web3Options, EthereumAccountOptions accountOptions = null) { if (accountOptions == null || string.IsNullOrEmpty(accountOptions.PrivateKey)) { Web3 = new Web3.Web3(web3Options.Url); } else { Web3 = new Web3.Web3(new Account(accountOptions.PrivateKey), web3Options.Url); } }
public override void ConfigureServices(WebHostBuilderContext context, IServiceCollection services) { // Bind the connection options based on the current configuration. var web3Options = new Web3ConnectionOptions(); context.Configuration.GetSection(Web3ConnectionOptions.ConfigurationSection) .Bind(web3Options); var accountOptions = new EthereumAccountOptions(); context.Configuration .GetSection(EthereumAccountOptions.ConfigurationSection) .Bind(accountOptions); // Build the web3 service from the connection options. var web3Service = new Web3Service(web3Options, accountOptions); // Add the web3 service to the service collection. services.AddSingleton(web3Service); }