Working with EVMNS
Before you can begin interacting with EVMNS, you will need to obtain a reference to the EVMNS registry. How you do this depends on the library you are using.
Example code for the Javascript-based APIs (ethers.js) here expect that they are being run inside a DApp browser, such as Chrome with metamask installed, which exposes the ethereum
object.
// GetContract
const EVMRegistrarController = await ethers.getContract('EVMRegistrarController', deployer)
const publicResolver = await ethers.getContract('PublicResolver', deployer)
// PublicResolver address
var resolver = publicResolver.address
var secret = '0x0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
var name = '123.evm'
var owner = '0x...'
var duration = 3600 * 24 * 365
// IsAvailable
const available = await EVMRegistrarController.available(name)
if (!available) return;
// Get commitment
const commitment = await EVMRegistrarController.makeCommitment(
name,
owner,
duration,
secret,
resolver,
[],
0,
0,
)
// Commit
await EVMRegistrarController.commit(commitment)
// WaitSeconds 15s
// Register
var value = 5 * Math.pow(10, 18) // 5 eos
const res = await EVMRegistrarController.register(
name,
owner,
duration,
secret,
resolver,
[],
false,
0,
{ value },
)
Currently, ethers.js support for EVMNS name resolution. In this library, you can input an EVMNS name wherever an address is required, eliminating the need for direct interaction with EVMNS APIs unless you choose to manually resolve names or perform other EVMNS operations.
Last updated