Step 2 - Set up
Having installed Ethers JS in the previous step, in your dApp's code, import the package using
import {ethers} from 'ethers'
or
const ethers = require('ethers')
This will allow you to use the functions and methods inside Ethers JS.
Next, we can start interacting with the dotNames registry contract.
The contract addresses for various dotNames' extensions can be found here:
.eth (Ethereum chain): 0x14603c5Fb32cB17604c91f752430368eDEF33dcF
.arb (Arbitrum One): 0x4059894a72aD1b910d45bDFB3762ABBeAa6D6127
.shib (Ethereum Chain): 0x5e294C6C77D578a6eaBF8f42b6A5Bd4D68e46F87
The first step in interacting with these contracts will be to make a connection to the blockchain using the user's connected wallet.
To achieve this, we will make use of the window.ethereum
object given to us by ethers.
Inside of a function, we'll say:
With this, we have created an abstraction of the contract within our local code, and can now use this contract's functions.
If you use React JS, you can globalize this contract object by using state variables. Here's an example:
create the state
const [contractAddress, setContractAddress] = useState(null)
set the state after the contract abstraction is complete.
With this, we can now use the contract address globally.
Now let's call some functions!
Last updated