As the below picture display.

If I know the raw transaction data, then how can I sign this transaction with the ethers.js?

enter image description here



The raw transaction data is display on the metamask.

I use a dapp.

And in the app, every time widthdraw, it will return the raw data, and need I to confirm with the metamask, So I want to confirm the transaction with ethers.js.

enter image description here

enter image description here


I had tried as these codes:

const ALCHEMY_GOERLI_URL = 'https://mainnet.infura.io/v3/xxxxxx';
    const provider = new ethers.providers.JsonRpcProvider(ALCHEMY_GOERLI_URL);
    let wallet = new ethers.Wallet(params[1]);
    let walletiWithProvider = wallet.connect(provider)
    const nonce = await walletiWithProvider.getTransactionCount(params[0])
    let transaction = {
      to: params[0],
      gasLimit: '300000',
      maxPriorityFeePerGas: ethers.utils.parseUnits('5', 'gwei'),
      maxFeePerGas: ethers.utils.parseUnits('20', 'gwei'),
      nonce: nonce,
      chainId: 1,
      data: targets.payload,
      value: ethers.utils.parseEther(String(formInline.amount))
    let tx = await walletiWithProvider.sendTransaction(transaction)
    await tx.wait()

But this return a error:

processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":44,\"error\":{\"code\":-32602,\"message\":\"invalid argument 1: hex number \\u003e 64 bits\"}}", error={"code":-32602}, requestBody="{\"method\":\"eth_getTransactionCount\",\"params\":...)

I think this maybe the data is error.


Again Supplement

I want to withdraw the ERC20 token (not eth), and as the below codes, I just send eth to myself account.

Thanks for your help.

enter image description here

1 Answer 1


Infura RPC

     const network = process.env.ETHEREUM_NETWORK; // "goreli"

     const provider = new ethers.providers.InfuraProvider(
                           process.env.INFURA_API_KEY // infura api key
     const signer = new ethers.Wallet(process.env.SIGNER_PRIVATE_KEY, provider); // wallet private key

     const tx = await signer.sendTransaction({
        to: params[0],
        value: ethers.utils.parseEther(String(formInline.amount)),
        data: targets.payload

     await tx.wait();

References : referring to the Infura docs here, seems like what you need is the above extract. Create eip1559_tx.js

I was able to successfully do a 0 ether Transfer with a message using the above code

  • Thanks for you answer, but I had try as your codes. It also get errors. And I had added some detail to my question.
    – SylorHuang
    Commented Jan 1, 2023 at 11:59
  • seems like you are using infura as a RPC provider if I am correct? I will update my answer according to your edit. Commented Jan 1, 2023 at 13:02
  • Ok, Thanks very much. I will try as you code. And Then I will feedback result to you.
    – SylorHuang
    Commented Jan 2, 2023 at 2:37
  • It works, but I want to withdraw the ERC20 token (not eth), and as the codes, I just send eth to myself account. Please help, thanks. I had supplement the result to the question
    – SylorHuang
    Commented Jan 2, 2023 at 3:32
  • 1
    you are welcome:) Commented Jan 2, 2023 at 15:20

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.