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 thecommit
Function and send it as a transaction - I wait for 90 seconds
- I call
register
(passing in the same arguments I passed into makecommit
) 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):
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
Post a Comment