Skip to main content

ENS contract "register" function failing

I wanted to ask a question about my ENS domain register flow that im doing in node.js

It goes as follows :

  • I check and verify that the domain is available by calling available
  • I call makeCommitment
  • I pass the output from makeCommitment to the commit Function and send it as a transaction
  • I wait for 90 seconds
  • I call register (passing in the same arguments I passed into make commit) and send it as a transaction with the value being the rentPrice of the domain

The last step is where it fails.

Here is the output of makeCommitment when manually passing in the same data my coded uses (check image):

enter image description here

The commitment my code generated matches the one in the image
commitment : 0x3f39cd6bbf253c6cc72e623a619b69dad1edee34889a7f95e7a67f5e621243de

Here is my transaction to the commit call

Here is the Failing transaction to register call

The code is attached. it uses ethers.js version 5.7.2

This is the Controller contract address I'm using : 0xCc5e7dB10E65EED1BBD105359e7268aa660f6734

I'm using the ABI that is found on the contract page on etherscan (GOERLI network).

Any idea why register keeps failing ? I been trying to debug this for the past 3 days.

I also tried to post this in the ENS developer forums but i do not have permissions to post on that page.

Here is my code :

const { ethers } = require("ethers");

const ENSGetRegisterPriceForDuration = async (DOMAIN, years = 1) => {
  if (!DOMAIN) {
    return;
  }

  let provider = new ethers.providers.JsonRpcProvider(process.env.ETHEREUM_GOERLI);
  let Contract = new ethers.Contract(ENS_REGISTRAR.address, ENS_REGISTRAR.abi, provider);
  const [BigNumber] = await Contract.functions.rentPrice(DOMAIN, ONE_YEAR * years);
  const bigNumber = ethers.utils.formatEther(BigNumber[0]).toString();
  const decimalValue = bigNumber.toString();
  console.log(`Estimated cost for ${DOMAIN}.eth for a period of ${years} years : ${decimalValue} ETH`);
  return decimalValue;
};

const ENSIsAvailable = async (DOMAIN) => {
  if (!DOMAIN) {
    return;
  }

  let provider = new ethers.providers.JsonRpcProvider(process.env.ETHEREUM_GOERLI);
  let Contract = new ethers.Contract(ENS_REGISTRAR.address, ENS_REGISTRAR.abi, provider);
  const [result] = await Contract.functions.available(DOMAIN);
  console.log(`${DOMAIN}.eth is ${result ? "AVAILABLE" : "NOT AVAILABLE"}`);
  return result;
};

const makeCommitment = async (DOMAIN, years = 1) => {
  const provider = new ethers.providers.JsonRpcProvider(process.env.ETHEREUM_GOERLI);
  const privateKey = process.env.PRIVATE_KEY;
  const signer = new ethers.Wallet(privateKey, provider);

  const salt = ethers.utils.namehash(DOMAIN);

  let registrar = new ethers.Contract(ENS_REGISTRAR.address, ENS_REGISTRAR.abi, provider);

  const [commitment] = await registrar.functions.makeCommitment(
    DOMAIN,
    signer.address,
    ONE_YEAR * years, // 31536000
    salt,
    "0xd7a4F6473f32aC2Af804B3686AE8F1932bC35750",
    ["0x"],
    true,
    0,
  );
  console.log("commitment :", commitment, "\n", "salt :", salt);
  return commitment;
};
const commit = async (commitment) => {
  const provider = new ethers.providers.JsonRpcProvider(process.env.ETHEREUM_GOERLI);
  const privateKey = process.env.PRIVATE_KEY;
  const signer = new ethers.Wallet(privateKey, provider);

  let registrar = new ethers.Contract(ENS_REGISTRAR.address, ENS_REGISTRAR.abi, provider);

  const recieptCommit = await registrar.connect(signer).commit(commitment, { gasLimit: 50000 });
  return recieptCommit;
};

const register = async (DOMAIN, years = 1) => {
  const provider = new ethers.providers.JsonRpcProvider(process.env.ETHEREUM_GOERLI);
  const privateKey = process.env.PRIVATE_KEY;
  const signer = new ethers.Wallet(privateKey, provider);

  let registrar = new ethers.Contract(ENS_REGISTRAR.address, ENS_REGISTRAR.abi, provider);
  const salt = ethers.utils.namehash(DOMAIN);
  const registerTxn = await registrar.populateTransaction.register(
    DOMAIN,
    signer.address,
    ONE_YEAR * years,
    salt,
    "0xd7a4F6473f32aC2Af804B3686AE8F1932bC35750",
    ["0x"],
    true,
    0,
    {
      value: ethers.utils.parseEther(
        (parseFloat(await ENSGetRegisterPriceForDuration(DOMAIN, years)) * 1.1).toFixed(6).toString(),
      ),
      gasLimit: 500000,
    },
  );

  //Returns a Promise which resolves to the transaction.
  let sendTxnRegister = await signer.sendTransaction(registerTxn);

  //Resolves to the TransactionReceipt once the transaction has been included in the chain for x confirms blocks.
  let recieptRegister = await sendTxnRegister.wait();

  if (recieptRegister) {
    console.log(
      " - Transaction is mined - " + "\n" + "Transaction Hash:",
      (await sendTxnRegister.hash) +
        "\n" +
        "Block Number: " +
        (await recieptRegister).blockNumber +
        "\n" +
        "Navigate to  https://goerli.etherscan.io/tx/" +
        (await sendTxnRegister).hash,
      "to see your transaction",
    );
  }
};

const ENSBuy = async (DOMAIN, years = 1) => {
  if (await ENSIsAvailable(DOMAIN)) {
    const commitment = await makeCommitment(DOMAIN, years);
    if (commitment) {
      const committed = await commit(commitment);
      if (committed) {
        setTimeout(async () => {
          await register(DOMAIN, years);
        }, 90000);
      }
    }
  }
};

ENSBuy("kw3", 1);
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Yemw74r

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data