Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: return type of sendTransaction in docs #7386

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.ignoreGas# = true
* web3.eth.sendTransaction(transaction, undefined, { ignoreGas#: 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
Loading