This package provides an easy-to-use interface to the Ethereum Name Service. Example usage: var ENS = require('ethereum-ens'); var Web3 = require('web3');
var web3 = new Web3();
var ens = new ENS(web3, '0x1234abc...');
var address = ens.resolver('foo.eth').addr();
Throughout this module, the same optionally-asynchronous pattern as web3 is used: all functions that call web3 take a callback as an optional last argument; if supplied, the function returns nothing, but instead calls the callback with (err, result) when the operation completes.
Functions that create transactions also take an optional 'options' argument; this has the same parameters as web3.
Meta
- author: Nick Johnson <nick@ethereum.org>
- license: LGPL
Constructs a new ENS instance.
Parameters
web3
object A web3 instance to use to communicate with the blockchain.address
address The address of the ENS registry.
resolver returns a resolver object for the specified name, throwing
ENS.NameNotFound if the name does not exist in ENS.
Resolver objects are wrappers around web3 contract objects, with the
first argument - always the node ID in an ENS resolver - automatically
supplied. So, to call the addr(node)
function on a standard resolver,
you only have to call addr()
.
Parameters
name
string The name to look up.abi
list Optional. The JSON ABI definition to use for the resolver. if none is supplied, a default definition implementinghas
,addr
andsetAddr
is supplied.callback
function Optional. If specified, the function executes asynchronously.
Returns any The resolver object if callback is not supplied.
setResolver sets the address of the resolver contract for the specified name. The calling account must be the owner of the name in order for this call to succeed.
Parameters
name
string The name to updateaddress
address The address of the resolveroptions
object An optional dict of parameters to pass to web3.callback
function An optional callback; if specified, the function executes asynchronously.addr
Returns any The transaction ID if callback is not supplied.
owner returns the address of the owner of the specified name.
Parameters
name
string The name to look up.callback
function An optional callback; if specified, the function executes asynchronously.
Returns any The resolved address if callback is not supplied.
setOwner sets the owner of the specified name. Only the owner may call setResolver or setSubnodeOwner. The calling account must be the current owner of the name in order for this call to succeed.
Parameters
name
string The name to updateaddress
address The address of the new owneroptions
object An optional dict of parameters to pass to web3.callback
function An optional callback; if specified, the function executes asynchronously.addr
Returns any The transaction ID if callback is not supplied.
setSubnodeOwner sets the owner of the specified name. The calling account must be the owner of the parent name in order for this call to succeed - for example, to call setSubnodeOwner on 'foo.bar.eth', the caller must be the owner of 'bar.eth'.
Parameters
name
string The name to updateaddress
address The address of the new owneroptions
object An optional dict of parameters to pass to web3.callback
function An optional callback; if specified, the function executes asynchronously.addr
Returns any The transaction ID if callback is not supplied.
namehash implements ENS' name hash algorithm.
Parameters
name
string The name to hash
Returns any The computed namehash, as a hex string.