Skip to main content

sendTransaction

Callable


  • Type parameters

    • ReturnFormat: DataFormat
    • ResolveType = { blockHash: ByteTypes[ReturnFormat[bytes]]; blockNumber: NumberTypes[ReturnFormat[number]]; contractAddress?: string; cumulativeGasUsed: NumberTypes[ReturnFormat[number]]; effectiveGasPrice?: NumberTypes[ReturnFormat[number]]; from: string; gasUsed: NumberTypes[ReturnFormat[number]]; logs: { readonly id?: string | undefined; readonly removed?: boolean | undefined; readonly logIndex?: NumberTypes[ReturnFormat["number"]] | undefined; ... 6 more ...; readonly topics?: ByteTypes[ReturnFormat["bytes"]][] | undefined; }[]; logsBloom: ByteTypes[ReturnFormat[bytes]]; root: ByteTypes[ReturnFormat[bytes]]; status: NumberTypes[ReturnFormat[number]]; to: string; transactionHash: ByteTypes[ReturnFormat[bytes]]; transactionIndex: NumberTypes[ReturnFormat[number]]; type?: NumberTypes[ReturnFormat[number]] }

    Parameters

    Returns Web3PromiEvent<ResolveType, SendTransactionEvents<ReturnFormat>>

    If awaited or .thend (i.e. the promise resolves), the transaction hash is returned.

    const transaction = {
    from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
    to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
    value: '0x1'
    }

    const transactionHash = await web3.eth.sendTransaction(transaction);
    console.log(transactionHash);
    > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f

    web3.eth.sendTransaction(transaction).then(console.log);
    > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f

    web3.eth.sendTransaction(transaction).catch(console.log);
    > <Some TransactionError>

    // Example using options.ignoreGasPricing = true
    web3.eth.sendTransaction(transaction, undefined, { ignoreGasPricing: true }).then(console.log);
    > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f

    Otherwise, a Web3PromiEvent is returned which has several events than can be listened to using the .on syntax, such as:

    • sending
      web3.eth.sendTransaction(transaction).on('sending', transactionToBeSent => console.log(transactionToBeSent));
      > {
      from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
      to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
      value: '0x1',
      gasPrice: '0x77359400',
      maxPriorityFeePerGas: undefined,
      maxFeePerGas: undefined
      }
    • sent
      web3.eth.sendTransaction(transaction).on('sent', sentTransaction => console.log(sentTransaction));
      > {
      from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
      to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
      value: '0x1',
      gasPrice: '0x77359400',
      maxPriorityFeePerGas: undefined,
      maxFeePerGas: undefined
      }
    • transactionHash
      web3.eth.sendTransaction(transaction).on('transactionHash', transactionHash => console.log(transactionHash));
      > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f
    • receipt
      web3.eth.sendTransaction(transaction).on('receipt', receipt => console.log(receipt));
      > {
      transactionHash: '0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f',
      transactionIndex: 0n,
      blockNumber: 2n,
      blockHash: '0xeb1565a08b23429552dafa92e32409f42eb43944f7611963c63ce40e7243941a',
      from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
      to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
      cumulativeGasUsed: 21000n,
      gasUsed: 21000n,
      logs: [],
      logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
      status: 1n,
      effectiveGasPrice: 2000000000n,
      type: 0n
      }
    • confirmation
      web3.eth.sendTransaction(transaction).on('confirmation', confirmation => console.log(confirmation));
      > {
      confirmations: 1n,
      receipt: {
      transactionHash: '0xb4a3a35ae0f3e77ef0ff7be42010d948d011b21a4e341072ee18717b67e99ab8',
      transactionIndex: 0n,
      blockNumber: 5n,
      blockHash: '0xb57fbe6f145cefd86a305a9a024a4351d15d4d39607d7af53d69a319bc3b5548',
      from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4',
      to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
      cumulativeGasUsed: 21000n,
      gasUsed: 21000n,
      logs: [],
      logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
      status: 1n,
      effectiveGasPrice: 2000000000n,
      type: 0n
      },
      latestBlockHash: '0xb57fbe6f145cefd86a305a9a024a4351d15d4d39607d7af53d69a319bc3b5548'
      }
    • error
      web3.eth.sendTransaction(transaction).on('error', error => console.log);
      > <Some TransactionError>