I have been developing some sort of Anti-MevBot and its the first time I see this error: TypeError: invalid value for Contract target (argument="target", value=null, code=INVALID_ARGUMENT, version=6.8.1)

Extra Info: { code: 'INVALID_ARGUMENT', argument: 'target', value: undefined, shortMessage: 'invalid value for Contract target' }

I'm using ethers.js 6.8.1 and node.js express 4.18.2 On a node js server 20.6.1

It occurs when I try to instantiate a Contract.

  const toeknInContract = new ethers.Contract(txDTO.tokenIn, erc20ABI, xProvider)

And I'm sure that the target contract exists.

Any clue?

1

There are 1 answers

0
Akeel Ahmed Qureshi On

The error message you are getting is indicating that the provided value (txDTO.tokenIn) for the contract address is either null or undefined.

This field require a valid contract address for instantiate the contract.

please check that the value of txDTO.tokenIn is a valid before you pass it to the "ethers.Contract" constructor.You can console and check the value before passing.

I have attached a link and screenshot of the code which is causing this error.

Screenshot: enter image description here

Link:

https://github.com/ethers-io/ethers.js/blob/98910ba01efa774710eefa5a6a5836a8b271c654/src.ts/contract/contract.ts#L685C1-L685C1