from the code below, I can add pool successful in testnet, but when I change the router to mainnet the transaction will be revert.
revert tx:
0x6de48db59f9e948ad361852e6875b8bf13c36b1e4322103faf91e78c871fd7d2
error:
reason: 'transaction failed',
code: 'CALL_EXCEPTION',
transactionHash: '0xf48e66fcf9786331c2fddf02cc60c0817d5f89c8db8d0af88554d177dfcbc440',
transaction: {
hash: '0xf48e66fcf9786331c2fddf02cc60c0817d5f89c8db8d0af88554d177dfcbc440',
type: 2,
accessList: [],
blockHash: null,
blockNumber: null,
transactionIndex: null,
confirmations: 0,
from: '0xF18054DBDE0e7fd744a41EaD4E36D8f6d9475dbb',
gasPrice: BigNumber { value: "1000000000" },
maxPriorityFeePerGas: BigNumber { value: "1000000000" },
maxFeePerGas: BigNumber { value: "1000000000" },
gasLimit: BigNumber { value: "3000000" },
to: '0x10ED43C718714eb63d5aA57B78B54704E256024E',
value: BigNumber { value: "10000000000000000" },
nonce: 50,
data: '0xf305d719000000000000000000000000247113c95196ae7ab874680d05ae1fa52311d43d00000000000000000000000000000000000000000052b7d2dcc80cd2e400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f18054dbde0e7fd744a41ead4e36d8f6d9475dbb000000000000000000000000000000000000000000000000000000006813ab26',
r: '0x45cc0ff4a4cbe06c098b57390b8d4d73761facb39022b045674562475220b4b3',
s: '0x041294c6278d51cac3606e9fe823ba6adbf156452689d1627046ab62f10324c3',
v: 1,
creates: null,
chainId: 56,
wait: [Function (anonymous)]
},
receipt: {
to: '0x10ED43C718714eb63d5aA57B78B54704E256024E',
from: '0xF18054DBDE0e7fd744a41EaD4E36D8f6d9475dbb',
contractAddress: null,
transactionIndex: 27,
gasUsed: BigNumber { value: "2911338" },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0x9d968c2d7da0ead5a47a797b1c8f69aeae19533942c1f8a06d386ac9790fabe1',
transactionHash: '0xf48e66fcf9786331c2fddf02cc60c0817d5f89c8db8d0af88554d177dfcbc440',
logs: [],
blockNumber: 48916833,
confirmations: 3,
cumulativeGasUsed: BigNumber { value: "6947375" },
effectiveGasPrice: BigNumber { value: "1000000000" },
status: 0,
type: 2,
byzantium: true
}
}
code:
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying contract with the account:", deployer.address);
const initialSupply = ethers.utils.parseUnits("1000000000", 18);
const Token = await ethers.getContractFactory("MyBEP20Token");
const token = await Token.deploy(initialSupply);
await token.deployed();
console.log("Token deployed to:", token.address);
const tokenAddress = token.address;
// test
const routerAddress = "0xD99D1c33F9fC3444f8101754aBC46c52416550D1";
// main
// const routerAddress = "0x10ED43C718714eb63d5aA57B78B54704E256024E";
const tokenAbi = [
"function approve(address spender, uint256 amount) public returns (bool)"
];
const tokenContract = new ethers.Contract(tokenAddress, tokenAbi, deployer);
const routerAbi = [
"function addLiquidityETH(address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline) external payable returns (uint amountToken, uint amountETH, uint liquidity)"
];
const router = new ethers.Contract(routerAddress, routerAbi, deployer);
const tokenDecimals = 18;
const amountTokenDesired = ethers.utils.parseUnits("100000000", tokenDecimals);
const bnbAmount = ethers.utils.parseEther("0.01");
console.log("Approving router to transfer tokens...");
const approveTx = await tokenContract.approve(routerAddress, amountTokenDesired, {
gasPrice: ethers.utils.parseUnits("10", "gwei")
});
await approveTx.wait();
console.log("Approval successful.");
const deadline = Math.floor(Date.now() / 1000) + (20 * 60);
console.log("Adding liquidity...");
const liquidityTx = await router.addLiquidityETH(
tokenAddress,
amountTokenDesired,
0,
0,
deployer.address,
deadline,
{ value: bnbAmount, gasLimit: 3000000 }
);
const receipt = await liquidityTx.wait();
console.log("Liquidity added successfully!");
console.log("Transaction receipt:", receipt);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error("Execution error:", error);
process.exit(1);
});