|
| 1 | +--- |
| 2 | +sidebar_position: 3 |
| 3 | +sidebar_label: 'Web3PromiEvent' |
| 4 | +--- |
| 5 | + |
| 6 | +# PromiEvent |
| 7 | + |
| 8 | +You can use Web3PromiEvent when you send transaction via `web3.eth.sendTransaction`, `web3.eth.sendSignedTransaction`, `contractDeployed.methods['methodName'](...methodParams).send` functions |
| 9 | + |
| 10 | +```ts |
| 11 | +web3.eth.sendTransaction({...}) |
| 12 | + .on('sending', (sending) => { |
| 13 | + // Sending example |
| 14 | + // 0x02f86d82053903849502f900849a9a0d16830186a0947ab80aeb6bb488b7f6c41c58e83ef248eb39c8828080c080a0b0fce643a6ca3077ee6b83590b1798d00edef99e2c65c1837daab88d46860887a07ca449a31b2430dbf21310b8c4491386762ade23e48c7cd0b70d315576374c7c |
| 15 | + }) |
| 16 | + .on('sent', (sent) => { |
| 17 | + // Sent example |
| 18 | + // 0x02f86d82053903849502f900849a9a0d16830186a0947ab80aeb6bb488b7f6c41c58e83ef248eb39c8828080c080a0b0fce643a6ca3077ee6b83590b1798d00edef99e2c65c1837daab88d46860887a07ca449a31b2430dbf21310b8c4491386762ade23e48c7cd0b70d315576374c7c |
| 19 | + }) |
| 20 | + .on('transactionHash', (transactionHash) => { |
| 21 | + // Transaction hash example |
| 22 | + // 0x6d85b2f07e7c8f2a7ce90a5bcfa3100c528f173f0707164434fb42d397d92d50 |
| 23 | + }) |
| 24 | + .on('confirmation', (confirmation) => { |
| 25 | + // Confirmation example |
| 26 | + // { |
| 27 | + // confirmations: 1n, |
| 28 | + // receipt: { |
| 29 | + // blockHash: '0x947b8c95dea7f0c643f2be0e9d1c3bec76c7f5146fdf34f5f1efe6d2cab5f568', |
| 30 | + // blockNumber: 22n, |
| 31 | + // cumulativeGasUsed: 21000n, |
| 32 | + // effectiveGasPrice: 2553565308n, |
| 33 | + // from: '0xe2597eb05cf9a87eb1309e86750c903ec38e527e', |
| 34 | + // gasUsed: 21000n, |
| 35 | + // logs: [], |
| 36 | + // logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', |
| 37 | + // status: 1n, |
| 38 | + // to: '0x7ab80aeb6bb488b7f6c41c58e83ef248eb39c882', |
| 39 | + // transactionHash: '0x3ec198ae10cf289b91210b4fd86a3b22cc9bcef16bca6beee21c35b76a2b7073', |
| 40 | + // transactionIndex: 0n, |
| 41 | + // type: 2n |
| 42 | + // }, |
| 43 | + // latestBlockHash: '0x947b8c95dea7f0c643f2be0e9d1c3bec76c7f5146fdf34f5f1efe6d2cab5f568' |
| 44 | + // } |
| 45 | + |
| 46 | + }) |
| 47 | + .on('receipt', (receipt) => { |
| 48 | + // Receipt example |
| 49 | + // { |
| 50 | + // blockHash: '0x135d14b724d90b97feec1e96df590ce9af762d424aea49d29e11feaa24fe02f1', |
| 51 | + // blockNumber: 23n, |
| 52 | + // cumulativeGasUsed: 21000n, |
| 53 | + // effectiveGasPrice: 2546893579n, |
| 54 | + // from: '0xe2597eb05cf9a87eb1309e86750c903ec38e527e', |
| 55 | + // gasUsed: 21000n, |
| 56 | + // logs: [], |
| 57 | + // logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', |
| 58 | + // status: 1n, |
| 59 | + // to: '0x7ab80aeb6bb488b7f6c41c58e83ef248eb39c882', |
| 60 | + // transactionHash: '0x9a6497fe4028d716e66a24ab7dfd3d1bcf136ba2ec26f427719b4ddaaff76fb7', |
| 61 | + // transactionIndex: 0n, |
| 62 | + // type: 2n |
| 63 | + // } |
| 64 | + |
| 65 | + }) |
| 66 | + .on('error', (error) => { |
| 67 | + // Error example |
| 68 | + // InvalidResponseError: Returned error: exceeds block gas limit |
| 69 | + // at Web3RequestManager._processJsonRpcResponse (.../web3_request_manager.js:193:23) |
| 70 | + // at Web3RequestManager.<anonymous> (.../web3_request_manager.js:112:29) |
| 71 | + // at Generator.next (<anonymous>) |
| 72 | + // at fulfilled (.../web3_request_manager.js:5:58) |
| 73 | + // at processTicksAndRejections (node:internal/process/task_queues:96:5) { |
| 74 | + // innerError: { code: -32000, message: 'exceeds block gas limit' }, |
| 75 | + // code: 101, |
| 76 | + // data: undefined, |
| 77 | + // request: { |
| 78 | + // jsonrpc: '2.0', |
| 79 | + // id: 'ea1f8fb4-fe86-4492-9d89-c6e31bf1c036', |
| 80 | + // method: 'eth_sendRawTransaction', |
| 81 | + // params: [ |
| 82 | + // '0x02f86e82053903849502f900849a9a0d168405f7c1f0947ab80aeb6bb488b7f6c41c58e83ef248eb39c8828080c001a0ddd93f5ce9a6a0de130dc660e65d2cdf8784148b8c91b83635b8458e96a767a3a028c48b048bf041e530ded63a0d2198855043f782ef0aa47391a2afa9c50a5ff1' |
| 83 | + // ] |
| 84 | + // } |
| 85 | + }); |
| 86 | + |
| 87 | + |
| 88 | +``` |
| 89 | + |
| 90 | +List of references: |
| 91 | + |
| 92 | +- [Web3PromiEvent](/api/web3-core/class/Web3PromiEvent) |
0 commit comments