Skip to content

Commit

Permalink
fix: return type of sendTransaction in docs (#7386)
Browse files Browse the repository at this point in the history
* fix: return type of sendTransaction in docs

* Fix Very Minor Typo in Docs

---------

Co-authored-by: Dan Forbes <[email protected]>
  • Loading branch information
krzysu and danforbes authored Nov 13, 2024
1 parent 0915cf4 commit 6af068f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_label: 'Infer Contract Types from JSON Artifact (TypeScript)'

:::tip
📝 This article is for **TypeScript** developers. So, if you are using JavaScript, you do not need to read this.
However, web3.js version 4.x has been rewritten in TypeScript. And we encorage you to use its strongly-typed features with TypeScript.
However, web3.js version 4.x has been rewritten in TypeScript. And we encourage you to use its strongly-typed features with TypeScript.
:::

Web3.js is a popular library used for interacting with EVM blockchains. One of its key features is the ability to invoke EVM smart contracts deployed on the blockchain. In this blog post, we will show how to interact with the smart contract in **TypeScript**, with a special focus on how to infer types from JSON artifact files.
Expand Down
84 changes: 63 additions & 21 deletions packages/web3-eth/src/web3_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,19 +1021,61 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
* value: '0x1'
* }
*
* const transactionHash = await web3.eth.sendTransaction(transaction);
* console.log(transactionHash);
* > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f
* const transactionReceipt = await web3.eth.sendTransaction(transaction);
* console.log(transactionReceipt);
* > {
* blockHash: '0x39cee0da843293ae3136cee0de4c0803745868b6e72b7cd05fba395bffa0ee85',
* blockNumber: 6659547n,
* cumulativeGasUsed: 1029036n,
* effectiveGasPrice: 6765796845n,
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
* gasUsed: 21000n,
* logs: [],
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
* status: 1n,
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
* transactionHash: '0x619de868dd73c07bd0c096adcd405c93c1e924fdf741e684a127a52324c28bb9',
* transactionIndex: 16n,
* type: 2n
*}
*
* web3.eth.sendTransaction(transaction).then(console.log);
* > 0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f
* > {
* blockHash: '0x39cee0da843293ae3136cee0de4c0803745868b6e72b7cd05fba395bffa0ee85',
* blockNumber: 6659547n,
* cumulativeGasUsed: 1029036n,
* effectiveGasPrice: 6765796845n,
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
* gasUsed: 21000n,
* logs: [],
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
* status: 1n,
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
* transactionHash: '0x619de868dd73c07bd0c096adcd405c93c1e924fdf741e684a127a52324c28bb9',
* transactionIndex: 16n,
* type: 2n
*}
*
* 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
* > {
* blockHash: '0x39cee0da843293ae3136cee0de4c0803745868b6e72b7cd05fba395bffa0ee85',
* blockNumber: 6659547n,
* cumulativeGasUsed: 1029036n,
* effectiveGasPrice: 6765796845n,
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
* gasUsed: 21000n,
* logs: [],
* logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
* status: 1n,
* to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c',
* transactionHash: '0x619de868dd73c07bd0c096adcd405c93c1e924fdf741e684a127a52324c28bb9',
* transactionIndex: 16n,
* type: 2n
*}
* ```
*
*
Expand All @@ -1042,24 +1084,24 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
* ```ts
* web3.eth.sendTransaction(transaction).on('sending', transactionToBeSent => console.log(transactionToBeSent));
* > {
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
* to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
* value: '0x1',
* gasPrice: '0x77359400',
* maxPriorityFeePerGas: undefined,
* maxFeePerGas: undefined
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
* to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
* value: '0x1',
* gasPrice: '0x77359400',
* maxPriorityFeePerGas: undefined,
* maxFeePerGas: undefined
* }
* ```
* - `sent`
* ```ts
* web3.eth.sendTransaction(transaction).on('sent', sentTransaction => console.log(sentTransaction));
* > {
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
* to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
* value: '0x1',
* gasPrice: '0x77359400',
* maxPriorityFeePerGas: undefined,
* maxFeePerGas: undefined
* from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4',
* to: '0x6f1DF96865D09d21e8f3f9a7fbA3b17A11c7C53C',
* value: '0x1',
* gasPrice: '0x77359400',
* maxPriorityFeePerGas: undefined,
* maxFeePerGas: undefined
* }
* ```
* - `transactionHash`
Expand Down Expand Up @@ -1090,8 +1132,8 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
* ```ts
* web3.eth.sendTransaction(transaction).on('confirmation', confirmation => console.log(confirmation));
* > {
* confirmations: 1n,
* receipt: {
* confirmations: 1n,
* receipt: {
* transactionHash: '0xb4a3a35ae0f3e77ef0ff7be42010d948d011b21a4e341072ee18717b67e99ab8',
* transactionIndex: 0n,
* blockNumber: 5n,
Expand All @@ -1105,8 +1147,8 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
* status: 1n,
* effectiveGasPrice: 2000000000n,
* type: 0n
* },
* latestBlockHash: '0xb57fbe6f145cefd86a305a9a024a4351d15d4d39607d7af53d69a319bc3b5548'
* },
* latestBlockHash: '0xb57fbe6f145cefd86a305a9a024a4351d15d4d39607d7af53d69a319bc3b5548'
* }
* ```
* - `error`
Expand Down

1 comment on commit 6af068f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 6af068f Previous: 0915cf4 Ratio
processingTx 22899 ops/sec (±6.71%) 21158 ops/sec (±9.09%) 0.92
processingContractDeploy 38849 ops/sec (±8.75%) 39840 ops/sec (±7.22%) 1.03
processingContractMethodSend 16613 ops/sec (±8.48%) 16219 ops/sec (±7.11%) 0.98
processingContractMethodCall 28617 ops/sec (±6.23%) 28092 ops/sec (±7.49%) 0.98
abiEncode 44694 ops/sec (±7.29%) 42384 ops/sec (±8.97%) 0.95
abiDecode 30690 ops/sec (±8.05%) 30530 ops/sec (±6.45%) 0.99
sign 1530 ops/sec (±3.39%) 1490 ops/sec (±3.70%) 0.97
verify 372 ops/sec (±0.57%) 364 ops/sec (±0.63%) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.