Step 3 - Resolving addresses

To resolve an address, we can check for whether or not the address is already included in our storage mapping. Here's some sample code using the Ethers JS methods we've used earlier, and our global contractAddress state.

Let's see an example

const searchForyourDomain = async () => {
    const fetchAddress = await contractAddress.domains(nameState.toString()); //nameState is the accepted input from the user
    if (fetchAddress.slice(0, 5) === "0x000") { //if the selected name belongs to the dead address, ie has not been minted yet
      //do stuff
    } else {
      //do other stuff
    }
  };

You can of course make the code yours by setting a loading animation while this function runs to update your frontend. In the below example, we set the actual Ethereum hexadecimal address gotten from the searchForyourDomain function to some state, and then use that address to execute the sending function.

Here's an example of all that.

First, we'll create some state.

const [actualAddress, setActualAddress] = useState(null)

const searchForyourDomain = async () => {
const fetchAddress = await contractAddress.domains(nameState.toString()); //nameState is the accepted input from the user
  if (fetchAddy.slice(0, 5) === "0x000") { //if the selected name belongs to the dead address, ie has not been minted yet
      alert('This name is not minted yet! Do not send any assets!')
  } else {
      setActualAddress(fetchAddress)
}

Now we can use that address we fetched to do things, like make transactions behind the scenes.

For a simple transaction, you can use the following code:

const makeERC20Transfer = async () => {
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const signer = provider?.getSigner();
    const gas = provider?.getGasPrice();
    let gasLimit = "0x100000";
    const contract = new ethers.Contract(erc20TokenAddress, erc20ContractAbi, signer);
      try {
        contract.transfer(actualAddress, erc20TokenAmount);
      } catch (err) {
        setError(true);
      }
  };

That's it! You've just resolved a dotName and made an ERC-20 token transaction with it!

Last updated