Minting of Fantom token with Hardhat fails

37 Views Asked by At

I've created an IBC token on Fantom using the Axelar portal, which allows mint/burn operations. Here's the token in question: https://testnet.interchain.axelar.dev/fantom/0xDEdbd54Ffc534a1aEC6D290E7FC5a337218D2708

Using the portal I can mint tokens but when I attempt it programmatically using Hardhat, it doesn't work. Here's the token I've created: Here's the code I'm employing:

const hre = require("hardhat");
const ABI = require("./utils/interchainTokenABI");

const tokenAddr = "0xDEdbd54Ffc534a1aEC6D290E7FC5a337218D2708"
const destAddr = "0xD5070f2a2C706C086407Ac8F3Bd4F21e3E46Cb99"

var main = async () => {
    var signers = await hre.ethers.getSigners()
    var token = new hre.ethers.Contract(tokenAddr, ABI, signers[0])

    var res = await token.mint(destAddr, 2000)
    console.log(JSON.stringify(res));
}

main().then(() => process.exit())

and my hardhat.config.js:

 require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config({ path: ".env" });

const PRIVATE_KEY = process.env.PRIVATE_KEY;

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.18",
  networks: {
    fantom: {
      url: "https://rpc.ankr.com/fantom_testnet",
      chainId: 4002,
      accounts: [PRIVATE_KEY],
    },
  },
};

I also have a .env file with a single line PRIVATE_KEY=... where the ellipsis is the private key I used to create the contract

now, when I run this I get a transaction hash, but I never receive receive the tokens (the tokens should be sent to the account that deployed the contract). here's the output:

{"_type":"TransactionResponse","accessList":[],"blockNumber":1,"blockHash":"0xfc8671a9f2d10caaf3753096cf5f9cdae9a020dd95f4439c1c3273c3a0b3a58c","blobVersionedHashes":null,"chainId":"31337","data":"0x40c10f19000000000000000000000000d5070f2a2c706c086407ac8f3bd4f21e3e46cb9900000000000000000000000000000000000000000000000000000000000007d0","from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","gasLimit":"30000000","gasPrice":"1875000000","hash":"0xb437d1a075f998664445d010241bb8e14f527ca62636a3b5f39e5f46c76799e8","maxFeePerGas":"2750000000","maxPriorityFeePerGas":"1000000000","maxFeePerBlobGas":null,"nonce":0,"signature":{"_type":"signature","networkV":null,"r":"0xf77742adb4d92b1c1d68b0465bceef51ab66e71ec509ad86e893b5a8b99a3289","s":"0x2cd87c119a2b1be0bcd2bce5af149d4758bc7cf1de9f8ea65058ec67b541904e","v":27},"to":"0xDEdbd54Ffc534a1aEC6D290E7FC5a337218D2708","type":2,"value":"0"}

I also tried specifying the token's Manager contract address instead. that fails too

finally, when I look for the transaction hash in the blockchain explorers (I've looked in both https://testnet.axelarscan.io and https://testnet.ftmscan.com/tx/ as I'm not sure where I should be looking), it's not there. so I'm guessing the transaction is not getting broadcast

help?

1

There are 1 best solutions below

1
On BEST ANSWER

By default, Hardhat uses its in-memory Hardhat Network. Your transactions are therefore being processed locally and are not being sent to the Fantom chain.

If running your script via the Hardhat CLI, use the network flag:

hardhat run path/to/script --network fantom

You can also override the default network in hardhat.config.js:

module.exports = { defaultNetwork: 'fantom', ... }