ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

invalid value for value.data (invalid data (argument="value", value="", code=INVALID_ARGUMENT, version=6.13.1))

Open ArchTaqi opened this issue 1 year ago • 2 comments

Ethers Version

6.13.1

Search Terms

No response

Describe the Problem

Encountering issue sending ETH between wallets via code, despite transaction success on Etherscan and wallet verification. Error prevents cascading transactions, which rely on this initial transaction's positive response. Tried various RPC providers without resolution. Seeking assistance to identify error source.

Code Snippet

const ethers = require('ethers');

const providerUrl = 'quick-node-mainnet-rpc';
const hot_wallet_privateKey ='';
const provider = new ethers.JsonRpcProvider(providerUrl);
const wallet = new ethers.Wallet(hot_wallet_privateKey, provider);


const nonce = async () => {
    const nonce = await wallet.getNonce();
    console.log(nonce);
    const recipientAddress = '0x95FD6074659D4aC99Fd7B5D5cae6afAcFb211a07';
    const amountToSend = ethers.parseEther('0.001'); // 0.1 ETH

    const transaction = {
        to: recipientAddress,
        value: amountToSend,
        nonce:nonce,
    };

    const test = async () => {
        const tx = await wallet.sendTransaction(transaction);
        await tx.wait(1);
        console.log('Transaction sent:', tx.hash);
    };

    try { test(); } catch (error) {
    console.error('Error sending transaction:', error);
    }
};
nonce();

Contract ABI

No response

Errors

Error: invalid value for value.data (invalid data (argument="value", value="", code=INVALID_ARGUMENT, version=6.13.1)) (value={ "accessList": [  ], "blockHash": null, "blockNumber": null, "chainId": "0x1", "from": "0x2B4E3Df272E05b5318C69C95274055973C36fE1D", "gas": "0x5208", "gasPrice": "0x77850d4a0", "hash": "0x9772deb5d7f3969ed4dd62a198c674e3a2b14d1517fef84e47cde962ed5eb9a3", "input": "", "maxFeePerGas": "0x77850d4a0", "maxPriorityFeePerGas": "0xf4240", "nonce": "0x66", "r": "0x0", "s": "0x0", "to": "0x95FD6074659D4aC99Fd7B5D5cae6afAcFb211a07", "transactionIndex": null, "type": "0x2", "v": "0x0", "value": "0x38d7ea4c68000" }, code=BAD_DATA, version=6.13.1)
    at makeError (/Users/muhammadtaqi/Projects/Backend/node_modules/ethers/lib.commonjs/utils/errors.js:129:21)
    at assert (/Users/muhammadtaqi/Projects/Backend/node_modules/ethers/lib.commonjs/utils/errors.js:149:15)
    at /Users/muhammadtaqi/Projects/Backend/node_modules/ethers/lib.commonjs/providers/format.js:57:39
    at formatTransactionResponse (/Users/muhammadtaqi/Projects/Backend/node_modules/ethers/lib.commonjs/providers/format.js:225:7)
    at JsonRpcProvider._wrapTransactionResponse (/Users/muhammadtaqi/Projects/Backend/node_modules/ethers/lib.commonjs/providers/abstract-provider.js:348:96)
    at JsonRpcProvider.getTransaction (/Users/muhammadtaqi/Projects/Backend/node_modules/ethers/lib.commonjs/providers/abstract-provider.js:782:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async checkReplacement (/Users/muhammadtaqi/Projects/Backend/node_modules/ethers/lib.commonjs/providers/provider.js:1058:27)
    at async TransactionResponse.wait (/Users/muhammadtaqi/Projects/Backend/node_modules/ethers/lib.commonjs/providers/provider.js:1152:13)
    at async test (/Users/muhammadtaqi/Projects/Backend/native-test.js:27:3) {
  code: 'BAD_DATA',
  value: {
    blockHash: null,
    blockNumber: null,
    from: '0x2B4E3Df272E05b5318C69C95274055973C36fE1D',
    gas: '0x5208',
    gasPrice: '0x77850d4a0',
    maxFeePerGas: '0x77850d4a0',
    maxPriorityFeePerGas: '0xf4240',
    hash: '0x9772deb5d7f3969ed4dd62a198c674e3a2b14d1517fef84e47cde962ed5eb9a3',
    input: '',
    nonce: '0x66',
    to: '0x95FD6074659D4aC99Fd7B5D5cae6afAcFb211a07',
    transactionIndex: null,
    value: '0x38d7ea4c68000',
    type: '0x2',
    accessList: [],
    chainId: '0x1',
    v: '0x0',
    r: '0x0',
    s: '0x0'
  },
  shortMessage: 'invalid value for value.data (invalid data (argument="value", value="", code=INVALID_ARGUMENT, version=6.13.1))'
}

Node.js v20.17.0

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli)

Environment (Other)

No response

ArchTaqi avatar Oct 07 '24 11:10 ArchTaqi

Following

usman-codora avatar Oct 07 '24 12:10 usman-codora

Obviously your data format is incorrect. You expect a hexadecimal string, but you provide an empty string. I believe this problem can be solved by switching nodes.

Maybe you can consider compatibility with empty strings, but that is a future plan.

jasonandjay avatar Oct 12 '24 06:10 jasonandjay

Was this ever resolved, I have the same issue but only with Trust Wallet, Its throwing this with Trust Wallet but not with any other wallet such as Rainbow or Uniswap, I've almost hit a wall where I need to axe Trust Wallet as a possibility via Walletconnect 2 through Reownappkit.

Ive tried hexlify etc, if its 0x it ends "", but 0x00 ends as "00", which is not valid, but the transaction actually goes through, I just don't get the return so I never find out the txhash to work with.

In the meantime I created simply a wrapper that catches the error payload which has a HASH in it anyway and records it if the hash isnt returned the normal way.

SteiniPe87 avatar Aug 09 '25 15:08 SteiniPe87

any solution for this ?

sajwanAshish avatar Nov 06 '25 12:11 sajwanAshish

any solution for this ?

There is no solution to this, my solution ended up being a dirty mix for the Trust Wallet one

// Trust Wallet hash recovery regex
const TRUST_HASH_REGEX = /0x[a-fA-F0-9]{64}/g;

    // Try to recover a hash (Trust Wallet & buggy providers)
    await clientLog("ATTEMPTING_HASH_RECOVERY");
    
    const guess =
      err?.data?.hash ||
      err?.data?.txHash ||
      err?.info?.transactionHash ||
      err?.error?.data?.originalError?.transactionHash ||
      err?.transactionHash ||
      err?.hash ||
      (TRUST_HASH_REGEX.exec(String(err?.message || ""))?.[0]);
      
    if (guess && /^0x[a-fA-F0-9]{64}$/.test(guess)) {
      await clientLog("HASH_RECOVERED_FROM_ERROR", guess);
      console.warn("Recovered tx hash from error path:", guess);
      return guess;
    }

Thats only because Trust Wallet somehow returns the txhash in the error data, but I never found a way to fix this with 0x 00x, I tried everything even with Claude Code it was not to be solved.

SteiniPe87 avatar Nov 07 '25 11:11 SteiniPe87