Ethereum: TypeError: invalid BytesLike value (argument=”value”, value=[ ], code=INVALID_ARGUMENT, version=6.10.0) in testing Raffle Contract

Ethereum TypeError: Invalid BytesLike value (argument=”value”, value=[ ], code=INVALID_ARGUMENT, version=6.10.0)

The error message you are seeing indicates that the network.provider object is passed an invalid argument when calling evm_increaseTime. This issue occurs because Number(interval) + 1 cannot be converted to a valid bytes value for evm_increaseTime.

Solution:

Ethereum: TypeError: invalid BytesLike value (argument=

To fix this issue, we need to ensure that Number(interval) + 1 can be successfully converted to an integer. Here is the corrected code snippet:

// ...

await network.provider.send('evm_increaseTime', [Number(interval) + 1]);

By using Number(interval) + 1, we ensure that the resulting value is a valid number, which is required by the evm_increaseTime function.

Additional tips:

  • Ensure that the latest version of the Ethereum contract is deployed on your testnet.
  • Ensure that your node provider (e.g. Infura, Alchemy) supports the latest version of the Ethereum contract.
  • Ensure that your deployment or contract call is properly formatted and does not contain any syntax errors.

Example use case:

Here is an updated example that shows how to use evm_increaseTime correctly:

const { ethers } = require('ethers');

// Create a new signer instance

const signer = await ethers.getSigner();

// Set the interval in seconds

const interval = 10; // Replace with the desired interval

// Get the current timestamp and add the interval to it

const currentTime = Date.now() / 1000;

let nextTime = currentTime + interval;

// Use evm_increaseTime correctly

await signer.sendTransaction({

from: '0xYourWalletAddress', // Replace with your wallet address

to: '0xContractAddress', // Replace with contract address

value: ethers.utils.parseEther('1'), // Replace with transaction amount

data: ['evm_increaseTime'],

});

// Wait for the transaction to be extracted

await network.provider.sendTransaction({ from: signer.address, date: [nextTime] });

In this example, we first calculate the current timestamp and add the interval to it. Then, we use evm_increaseTime correctly by passing a valid argument.

By following these steps and examples, you should be able to resolve the TypeError and successfully call evm_increaseTime on your Ethereum contract.

Leave a Reply

Your email address will not be published. Required fields are marked *