public async void ShouldResolveNameFromMainnet() { var web3 = new Web3.Web3("https://mainnet.infura.io"); var fullNameNode = new EnsUtil().GetNameHash("nickjohnson.eth"); var ensRegistryService = new ENSRegistryService(web3, "0x314159265dd8dbb310642f98f50c066173c1259b"); //get the resolver address from ENS var resolverAddress = await ensRegistryService.ResolverQueryAsync( new ResolverFunction() { Node = fullNameNode.HexToByteArray() }); Assert.Equal("0x1da022710df5002339274aadee8d58218e9d6ab5", resolverAddress); //using the resolver address we can create our service (should be an abstract / interface based on abi as we can have many) var resolverService = new PublicResolverService(web3, resolverAddress); //and get the address from the resolver var theAddress = await resolverService.AddrQueryAsync(new AddrFunction() { Node = fullNameNode.HexToByteArray() }); //Owner address var expectedAddress = "0xfdb33f8ac7ce72d7d4795dd8610e323b4c122fbb"; Assert.Equal(expectedAddress.ToLower(), theAddress.ToLower()); }
public async Task <string> GetAddress(string accountDomain) { if (!IsValidDomain(accountDomain)) { throw new ArgumentException("Invalid name.", nameof(accountDomain)); } try { var ensRegistryService = new ENSRegistryService(Web3Client, RnsRegistry); var fullNameNode = new EnsUtil().GetNameHash(accountDomain); var resolverAddress = await ensRegistryService.ResolverQueryAsync( new ResolverFunction() { Node = fullNameNode.HexToByteArray() }).ConfigureAwait(false); var resolverService = new PublicResolverService(Web3Client, resolverAddress); var theAddress = await resolverService .AddrQueryAsync(fullNameNode.HexToByteArray()) .ConfigureAwait(false); return(theAddress); } catch (Exception e) { return(null); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v0.1/publickeys/lookup")] HttpRequest req, [Table("%PublicKey:Storage:PublicKeyTable%", Connection = "PublicKey:Storage:Connection")] CloudTable table, ILogger log, ExecutionContext context) { IConfigurationRoot config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); var queryParam = (string)req.Query["q"]; var model = new PublicKeyLookupModel(); if (!string.IsNullOrEmpty(queryParam) && !AddressUtil.Current.IsValidEthereumAddressHexFormat(queryParam)) { var web3 = new Web3(config.GetValue <string>("Blockchain:Endpoint")); var nameHash = new EnsUtil().GetNameHash(queryParam); var ensRegistryService = new ENSRegistryService(web3, config.GetValue <string>("Blockchain:ENSRegistryService")); var resolverAddress = await ensRegistryService.ResolverQueryAsync( new ResolverFunction() { Node = nameHash.HexToByteArray() }); var resolverService = new PublicResolverService(web3, resolverAddress); var address = await resolverService.AddrQueryAsync(nameHash.HexToByteArray()); model.Ens = new EnsModel { Name = queryParam, Hash = nameHash, Resolver = resolverAddress }; model.Address = address; queryParam = address; } if (AddressUtil.Current.IsValidEthereumAddressHexFormat(queryParam)) { var entity = await FindPublicKey(table, queryParam); if (entity != null) { model.Address = entity.PartitionKey; model.PublicKey = entity.RowKey; } } return(string.IsNullOrEmpty(model.Address) && model.Ens == null ? new NotFoundObjectResult("Public key not found") : (IActionResult) new OkObjectResult(model)); }