Skip to main content

signTransaction

Callable


  • Type parameters

    Parameters

    Returns Promise<SignedTransactionInfoAPI>

    SignedTransactionInfoAPI, an object containing the RLP encoded signed transaction (accessed via the raw property) and the signed transaction object (accessed via the tx property).

    const transaction = {
    from: '0xe899f0130FD099c0b896B2cE4E5E15A25b23139a',
    to: '0xe899f0130FD099c0b896B2cE4E5E15A25b23139a',
    value: '0x1',
    gas: '21000',
    gasPrice: await web3Eth.getGasPrice(),
    nonce: '0x1',
    type: '0x0'
    }

    web3.eth.signTransaction(transaction).then(console.log);
    > {
    raw: '0xf86501843b9aca0182520894e899f0130fd099c0b896b2ce4e5e15a25b23139a0180820a96a0adb3468dbb4dce89fe1785ea9182e85fb56b399b378f82b93af7a8a12a4f9679a027d37d736e9bcf00121f78b2d10e4404fa5c45856d62b746574345f5cd278097',
    tx: {
    type: 0n,
    nonce: 1n,
    gasPrice: 1000000001n,
    gas: 21000n,
    value: 1n,
    v: 2710n,
    r: '0xadb3468dbb4dce89fe1785ea9182e85fb56b399b378f82b93af7a8a12a4f9679',
    s: '0x27d37d736e9bcf00121f78b2d10e4404fa5c45856d62b746574345f5cd278097',
    to: '0xe899f0130fd099c0b896b2ce4e5e15a25b23139a',
    data: '0x'
    }
    }

    web3.eth.signTransaction(transaction, { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log);
    > {
    raw: '0xf86501843b9aca0182520894e899f0130fd099c0b896b2ce4e5e15a25b23139a0180820a96a0adb3468dbb4dce89fe1785ea9182e85fb56b399b378f82b93af7a8a12a4f9679a027d37d736e9bcf00121f78b2d10e4404fa5c45856d62b746574345f5cd278097',
    tx: {
    type: 0,
    nonce: 1,
    gasPrice: 1000000001,
    gas: 21000,
    value: 1,
    v: 2710,
    r: '0xadb3468dbb4dce89fe1785ea9182e85fb56b399b378f82b93af7a8a12a4f9679',
    s: '0x27d37d736e9bcf00121f78b2d10e4404fa5c45856d62b746574345f5cd278097',
    to: '0xe899f0130fd099c0b896b2ce4e5e15a25b23139a',
    data: '0x'
    }
    }