0

I have this function in my contract:

 function removeRes(address _res) public onlyOwner {
        .
        .
        .
    }

I'm encoding ABI like:

const contractAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";

const selector = contract.interface.encodeFunctionData(
        "removeRes(address)",
        [contractAddress],
      );

I'm getting this error

Error: incorrect data length (argument=null, value="0x69a5b950000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266", code=INVALID_ARGUMENT, version=abi/5.7.0)

I used an online tool (https://abi.hashex.org) and it gave the same value ("0x69a5b950000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266")

3 Answers 3

1

These are scripts I tried.
(I think it's not ideal to continue the exchange here multiple times, so I'll present this source code and conclude my remarks. I apologize if it doesn't get resolved.)

In Solidity:

pragma solidity >=0.7.0 <0.9.0;

contract RemoveRes {

    address private owner;
    address public passedByRemoveRes;

    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    constructor() {
        owner = msg.sender;
    }

    function removeRes(address _res) public onlyOwner {
        passedByRemoveRes = _res;
    }
}

In TS script. (I customized prepared script "deploy_with_ethers.ts" in IDE)

import { deploy } from './ethers-lib'

let contract;

(async () => {

  try {
    contract = await deploy('RemoveRes', [])
    console.log(`address: ${contract.address}`)
  } catch (e) {
    console.log(e.message)
  }

  const contractAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
  const selector = contract.interface.encodeFunctionData(
          "removeRes(address)",
          [contractAddress],
        );
  console.log(selector);

})();
2
  • Thankyou very much, I appreciate your responses throughout! Unfortunately this did not solve the problem, please see my answer below. Nov 9 at 13:41
  • 1
    I couldn't be of much help, but I'm relieved to hear that the issue has been resolved. I also learned something from this. Thank you very much. Nov 9 at 14:04
0

How about remove (address) from 1st parameter ?

const selector = contract.interface.encodeFunctionData(
        "removeRes",  // <--- change here.
        [contractAddress],
      );
6
  • Tried, it returns Error: incorrect data length (argument=null, value="0x69a5b950000000000000000000000000cae47bed7ec4a7598a06639a63e724204a759161", code=INVALID_ARGUMENT, version=abi/5.7.0) Nov 9 at 10:21
  • Thank you for trying it out. I'm sorry it didn't work. By the way, is the extra comma after the second argument still there? [contractAddress], <---- here Nov 9 at 10:35
  • Yes, Prettier automatically puts it after saving the file. Nov 9 at 10:55
  • Thank you for your response. Can you try removing that extra comma and see if it works? I'm concerned that the "argument=null" description in the error message might be causing the issue. Nov 9 at 11:04
  • Sure, thanks! I tried with and without param after removing the comma and still get the same error. Nov 9 at 11:08
0

This is what worked for me. I don't really have some reference from some documentation or anything, but I got to this solution based on some recent working examples of code for similar use cases.

 const selector = paymaster.interface.encodeFunctionData(
        "removeRes(address)",
        [contractAddress],
      ).substr(0,10);

Update: After digging further in the problem, I understand what the problem is. I was supposed to get the function selector and use it in my code.

For context, here's my code:

const selector = paymaster.interface.encodeFunctionData(
        "removeRestriction(address)",
        ["0xcAE47Bed7ec4A7598a06639A63e724204a759161"],
      );

const result = await anotherContract.functions
        .createRes(data.name, [address], [selector], [true])
        .then((r) => r.wait());
      return result;

This selector should be the first 4 bytes, which substr(0, 10) would return.

I was mislead by the error message and did not pay much attention to next lines of code, hence this code wasn't a part of my question description too.

Your Answer

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

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