1

I want to send transaction via ethers and wallet connected to metamask with following code:

 async redeemAllocation(idoId: number) {
    const IRoot = new ethers.utils.Interface(JSON.stringify(RootAbi))
    const addrRoot = "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
    const smcRoot = new ethers.Contract(addrRoot, IRoot)
    const investorIndex = await smcRoot.investorIndexFromProject(await this.signer!.getAddress(), idoId);
    let project = await smcRoot.projectById(idoId);
    const amount = project.amounts[investorIndex];

    const data = IRoot.encodeFunctionData("redeemAllocation", [idoId, amount]);

    this.signer!.sendTransaction({to: addrRoot, data: data}).then(async (tx) => {
      console.log('transaction sended')
  
      project = await smcRoot.projectById(idoId);
      console.log(project.redeemed[investorIndex])
    });

And get an error saying Errors encountered in param 1: Invalid value "0x-a1a" supplied to : (QUANTITY | { blockNumber: QUANTITY } | { blockHash: DATA, requireCanonical: boolean | undefined } | "earliest" | "latest" | "pending")/0: QUANTITY, Invalid value "0x-a1a" supplied to : (QUANTITY | { blockNumber: QUANTITY } | { blockHash: DATA, requireCanonical: boolean | undefined } | "earliest" | "latest" | "pending")/1: { blockNumber: QUANTITY }, Invalid value "0x-a1a" supplied to : (QUANTITY | { blockNumber: QUANTITY } | { blockHash: DATA, requireCanonical: boolean | undefined } | "earliest" | "latest" | "pending")/2: { blockHash: DATA, requireCanonical: boolean | undefined }, Invalid value "0x-a1a" supplied to : (QUANTITY | { blockNumber: QUANTITY } | { blockHash: DATA, requireCanonical: boolean | undefined } | "earliest" | "latest" | "pending")/3: "earliest" | "latest" | "pending".

redeemAllocation abi:

  {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "projectId",
          "type": "uint256"
        },
        {
          "internalType": "uint256",
          "name": "amount",
          "type": "uint256"
        }
      ],
      "name": "redeemAllocation",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    },

I guess the problem can be in IRoot.encodeFunctionData, but still don't get the reason clearly.

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented Mar 18, 2022 at 16:13

1 Answer 1

0

I don't know if your error is this, but Interface constructor gets an ABI without a parse. It doesn't need a JSON.parse every time for ABI.

Change this:
const IRoot = new ethers.utils.Interface(JSON.stringify(RootAbi))

To this:
const IRoot = new ethers.utils.Interface(RootAbi)

Source: https://docs.ethers.io/v5/api/utils/abi/interface/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.