ENS
This class is designed to interact with the ENS system on the Ethereum blockchain.
For using ENS package, first install Web3 package using: npm i web3
or yarn add web3
based on your package manager, after that ENS features can be used as mentioned in following snippet.
import { Web3 } from 'web3';
const web3 = new Web3('https://127.0.0.1:4545');
console.log(await web3.eth.ens.getAddress('ethereum.eth'))
For using individual package install web3-eth-ens
packages using: npm i web3-eth-ens
or yarn add web3-eth-ens
. This is more efficient approach for building lightweight applications.
import { ENS } from 'web3-eth-ens';
const ens = new ENS(undefined,'https://127.0.0.1:4545');
console.log(await ens.getAddress('vitalik.eth'));
Hierarchy
-
Web3Context
<EthExecutionAPI
&Web3NetAPI
>↳
ENS
Constructors
constructor
• new ENS(registryAddr?
, provider?
): ENS
Use to create an instance of ENS
Parameters
Name | Type | Description |
---|---|---|
registryAddr? | string | (Optional) The address of the ENS registry (default: mainnet registry address) |
provider? | string | LegacyRequestProvider | LegacySendProvider | LegacySendAsyncProvider | EIP1193Provider <EthExecutionAPI & Web3NetAPI > | Web3BaseProvider <EthExecutionAPI & Web3NetAPI > | SimpleProvider <EthExecutionAPI & Web3NetAPI > | MetaMaskProvider <EthExecutionAPI & Web3NetAPI > | Web3ContextObject <EthExecutionAPI & Web3NetAPI , any > | (Optional) The provider to use for the ENS instance |
Returns
Example
const ens = new ENS(
"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
"http://localhost:8545"
);
console.log( ens.defaultChain);
> mainnet
Overrides
Web3Context<EthExecutionAPI & Web3NetAPI>.constructor
Properties
registryAddress
• registryAddress: string
The registryAddress property can be used to define a custom registry address when you are connected to an unknown chain. It defaults to the main registry address.
Accessors
BatchRequest
• get
BatchRequest(): Object
Will return the Web3BatchRequest constructor.
Returns
Object
Inherited from
Web3Context.BatchRequest
blockHeaderTimeout
• get
blockHeaderTimeout(): number
The blockHeaderTimeout is used over socket-based connections. This option defines the amount seconds it should wait for 'newBlockHeaders'
event before falling back to polling to fetch transaction receipt.
Default is 10
seconds.
Returns
number
Inherited from
Web3Context.blockHeaderTimeout
• set
blockHeaderTimeout(val
): void
Will set the blockHeaderTimeout
Parameters
Name | Type |
---|---|
val | number |
Returns
void
Inherited from
Web3Context.blockHeaderTimeout
contractDataInputFill
• get
contractDataInputFill(): "input"
| "data"
| "both"
The contractDataInputFill
options property will allow you to set the hash of the method signature and encoded parameters to the property
either data
, input
or both within your contract.
This will affect the contracts send, call and estimateGas methods
Default is input
.
Returns
"input"
| "data"
| "both"
Inherited from
Web3Context.contractDataInputFill
• set
contractDataInputFill(val
): void
Will set the contractDataInputFill
Parameters
Name | Type |
---|---|
val | "input" | "data" | "both" |
Returns
void