diff --git a/.github/workflows/black_box_tests.yml b/.github/workflows/black_box_tests.yml index 0d87844cb6b..19c84cee6dd 100644 --- a/.github/workflows/black_box_tests.yml +++ b/.github/workflows/black_box_tests.yml @@ -10,7 +10,7 @@ jobs: build: strategy: matrix: - node: [18, 16] + node: [18] name: Build Packages runs-on: ubuntu-latest steps: @@ -36,7 +36,7 @@ jobs: strategy: fail-fast: false matrix: - node: [18, 16] + node: [18] mode: ['http', 'ws'] backend: ['geth', 'infura'] steps: diff --git a/.github/workflows/e2e_network_tests.yml b/.github/workflows/e2e_network_tests.yml index 58adb0ee4bf..508c45caee9 100644 --- a/.github/workflows/e2e_network_tests.yml +++ b/.github/workflows/e2e_network_tests.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 cache: yarn - run: yarn - run: tar -czf /tmp/web3-16.js.tar.gz --exclude="./.git" ./ @@ -41,7 +41,7 @@ jobs: steps: - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - uses: actions/download-artifact@v3 with: name: web3-16.js.tar.gz diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eba8930d2b..25645330a25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2581,3 +2581,71 @@ If there are any bugs, improvements, optimizations or any new feature proposal f - `populateTransaction` was added to contract methods (#7124) - Contract has `setTransactionMiddleware` and `getTransactionMiddleware` for automatically passing to `sentTransaction` for `deploy` and `send` functions (#7138) + +## [4.11.0] + +### Fixed + +#### web3-eth-abi + +- fix encodedata in EIP-712 (#7095) + +#### web3-utils + +- `_sendPendingRequests` will catch unhandled errors from `_sendToSocket` (#6968) + +#### web3-eth + +- Fixed geth issue when running a new instance, transactions will index when there are no blocks created (#7098) + +### Changed + +#### web3-eth-accounts + +- baseTransaction method updated (#7095) + +#### web3-providers-ws + +- Update dependancies (#7109) + +#### web3-plugin-example + +- Dependencies updated + +#### web3-rpc-providers + + - Change request return type `Promise` to `Promise>` (#7102) + +### Added + +#### web3-eth-contract + +- `populateTransaction` was added to contract methods (#7124) +- Contract has `setTransactionMiddleware` and `getTransactionMiddleware` for automatically passing to `sentTransaction` for `deploy` and `send` functions (#7138) + +#### web3-rpc-providers + + - When error is returned with code 429, throw rate limit error (#7102) + +#### web3 + +- `web3.eth.Contract` will get transaction middleware and use it, if `web3.eth` has transaction middleware. (#7138) + +## [4.11.1] + +### Fixed + +#### web3-errors + +- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905) + +#### web3-eth + +- Adds transaction property to be an empty list rather than undefined when no transactions are included in the block (#7151) +- Change method `getTransactionReceipt` to not be casted as `TransactionReceipt` to give proper return type (#7159) + +#### web3 + +- Remove redundant constructor of contractBuilder (#7150) + +## [Unreleased] \ No newline at end of file diff --git a/docs/docs/guides/wallet/metamask-react.md b/docs/docs/guides/wallet/metamask-react.md index c8c9a3604ae..8cdd7c70ba8 100644 --- a/docs/docs/guides/wallet/metamask-react.md +++ b/docs/docs/guides/wallet/metamask-react.md @@ -1,5 +1,5 @@ --- -sidebar_position: 4 +sidebar_position: 5 sidebar_label: 'Tutorial: Connecting to Metamask with React' --- diff --git a/docs/docs/guides/wallet/metamask-vanilla.md b/docs/docs/guides/wallet/metamask-vanilla.md index da930b07fad..ef55e9bcf8c 100644 --- a/docs/docs/guides/wallet/metamask-vanilla.md +++ b/docs/docs/guides/wallet/metamask-vanilla.md @@ -1,5 +1,5 @@ --- -sidebar_position: 3 +sidebar_position: 4 sidebar_label: 'Tutorial: Connecting to Metamask with Vanilla JS' --- diff --git a/docs/docs/guides/wallet/tx-types.md b/docs/docs/guides/wallet/tx-types.md new file mode 100644 index 00000000000..1e58a6b840a --- /dev/null +++ b/docs/docs/guides/wallet/tx-types.md @@ -0,0 +1,280 @@ +--- +sidebar_position: 3 +sidebar_label: 'Transaction Types' +--- + +# Transactions + +In this tutorial, we will explore how to send different types of [transactions](https://ethereum.org/en/developers/docs/transactions/) using web3.js, focusing on Ethereum's evolving transaction formats. We'll start with [legacy transactions (Transaction Type 0)](#transaction-type-0-legacy). Next, we'll delve into Transaction [Type 1 (EIP-2930)](#transaction-type-1-eip-2930), which introduces access lists to optimize gas usage. Finally, we'll cover [Transaction Type 2 (EIP-1559)](#transaction-type-2-eip-1559), the current default, which allows users to specify maximum fees and priority tips for more efficient and cost-effective transactions. Each section will include practical code examples to demonstrate sending raw transactions and interacting with ERC20 tokens on the Sepolia test network + +:::note +Web3.js uses transaction type 2 by default +::: + +## Transaction Type 0 (Legacy) + +### Raw Transaction + +A Legacy Transaction refers to a transaction that was created using an older version of Ethereum's transaction format, also known as "transaction type 0". This transaction format was used before the EIP-1559 upgrade, which was implemented in August 2021. + +```ts +import { Web3 } from "web3"; + +const web3 = new Web3("https://rpc2.sepolia.org"); // RPC node url + +async function txLegacy() { + const wallet = web3.eth.wallet.add("YOUR_PRIVATE_KEY"); // make sure you have funds + + const sender = wallet[0].address; + const recipient = "0x807BFe4940016B5a7FdA19482042917B02e68359"; + const value = 1; // wei + const nonce = await web3.eth.getTransactionCount(sender); + const gas = 21000; + const gasPrice = await web3.eth.getGasPrice(); + + const tx = { + from: sender, + to: recipient, + value, + nonce, + gas, + gasPrice, + // highlight-next-line + type: 0, + }; + + const txReceipt = await web3.eth.sendTransaction(tx); + console.log("Tx hash", txReceipt.transactionHash); +} + +txLegacy(); +``` + +### ERC20 Interaction + +```ts +import { Web3 } from "web3"; + +const web3 = new Web3("https://rpc2.sepolia.org"); + +//WETH token in Sepolia https://sepolia.etherscan.io/address/0xfff9976782d46cc05630d1f6ebab18b2324d6b14#code +const ADDRESS_WETH_SEPOLIA = "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14"; +const ABI = [ + { + constant: false, + inputs: [ + { + name: "dst", + type: "address", + }, + { + name: "wad", + type: "uint256", + }, + ], + name: "transfer", + outputs: [ + { + name: "", + type: "bool", + }, + ], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, +]; + +async function transfer() { + //initialize wallet + const wallet = web3.eth.accounts.wallet.add("YOUR_PRIVATE_KEY"); //make sure you have WETH tokens in the Sepolia network + //you can swap Sepolia tokens for WETH here https://app.uniswap.org/swap?chain=sepolia + + //initialize WETH contract in sepolia + const myERC20 = new web3.eth.Contract(ABI, ADDRESS_WETH_SEPOLIA); + + const TO = "0xEA9eEca67682Cd9c6Ce3DdD1681049D7A897289F"; //address to send the tokens to + const VALUE = 1; //wei value, dont forget to multiply by decimals + + //send transfer and specify the type + const txReceipt = await myERC20.methods.transfer(TO, VALUE).send({ + from: wallet[0].address, + // highlight-next-line + type: 0, + }); + + console.log(txReceipt.transactionHash); + //=> 0x5f2087c22166f3a1909c40ce537dd564dc3d4c70c5be02f35c6406a628123b16 +} + +transfer(); +``` + +## Transaction Type 1 (EIP-2930) + +This EIP was introduced in April 2021, it introduces a feature called 'Access List.' This improvement allows saving gas on cross-contract calls by declaring in advance which contract and storage slots will be accessed. + +### Raw Transaction + +```ts +import { Web3 } from "web3"; + +const web3 = new Web3("https://rpc2.sepolia.org"); + +async function txEIP2930() { + const wallet = web3.eth.wallet.add("YOUR_PRIVATE_KEY"); + + const sender = wallet[0].address; + const contractAddress1 = "0x..."; + const gas = 500000; //could be higher + const gasPrice = await web3.eth.getGasPrice(); + const data = "0x9a67c8b100000000000000000000000000000000000000000000000000000000000004d0" + + + // highlight-start + //create access list using web3.eth + const accessListData = await web3.eth.createAccessList({ + from: sender, + to: contractAddress1, + data, + }); + // highlight-end + + console.log(accessListData) + /* + => + { + // highlight-start + "accessList": [ + { + "address": "0x15859bdf5aff2080a9968f6a410361e9598df62f", + "storageKeys": [ + "0x0000000000000000000000000000000000000000000000000000000000000000" + ] + } + ], + // highlight-end + "gasUsed": "0x7671" + } + */ + + const tx = { + from: sender, + to: contractAddress1, //the contract we are calling + data, + gas, + gasPrice, + // highlight-next-line + type: 1, + // highlight-next-line + accessList: accessListData.accessList //access the object `accessList` + }; + + const txReceipt = await web3.eth.sendTransaction(tx); + + console.log("Tx hash", txReceipt.transactionHash); +} + +txEIP2930() +``` + +## Transaction Type 2 (EIP-1559) + +When a user creates an EIP-1559 transaction, they specify the maximum fee they are willing to pay `maxFeePerGas` as well as a tip `maxPriorityFeePerGas` to incentivize the miner. The actual fee paid by the user is then determined by the network based on the current demand for block space and the priority of the transaction. + +### Raw Transaction + +```ts +import { Web3 } from "web3"; + +const web3 = new Web3("https://rpc2.sepolia.org"); + +async function txEIP1559() { + const wallet = web3.eth.wallet.add("YOUR_PRIVATE_KEY"); //make sure you have funds + + const sender = wallet[0].address; + const recipient = "0x807BFe4940016B5a7FdA19482042917B02e68359"; + const value = 1; //wei + const nonce = await web3.eth.getTransactionCount(sender); + const gasLimit = 21000; + const maxFeePerGas = Number((await web3.eth.calculateFeeData()).maxFeePerGas); + const maxPriorityFeePerGas = Number((await web3.eth.calculateFeeData()).maxPriorityFeePerGas); + + const tx = { + from: sender, + to: recipient, + value, + nonce, + gasLimit, + maxFeePerGas, + maxPriorityFeePerGas, + // highlight-next-line + type: 2, + }; + + const txReceipt = await web3.eth.sendTransaction(tx); + console.log("Tx hash", txReceipt.transactionHash); +} + +txEIP1559(); +``` + +### ERC20 Interaction + +```ts +import { Web3 } from "web3"; + +const web3 = new Web3("https://rpc2.sepolia.org"); + +//WETH token in Sepolia https://sepolia.etherscan.io/address/0xfff9976782d46cc05630d1f6ebab18b2324d6b14#code +const ADDRESS_WETH_SEPOLIA = "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14"; +const ABI = [ + { + constant: false, + inputs: [ + { + name: "dst", + type: "address", + }, + { + name: "wad", + type: "uint256", + }, + ], + name: "transfer", + outputs: [ + { + name: "", + type: "bool", + }, + ], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, +]; + +async function transfer() { + //initialize wallet + const wallet = web3.eth.accounts.wallet.add("YOUR_PRIVATE_KEY"); //make sure you have WETH tokens in the Sepolia network + //you can swap Sepolia tokens for WETH here https://app.uniswap.org/swap?chain=sepolia + + //initialize WETH contract in sepolia + const myERC20 = new web3.eth.Contract(ABI, ADDRESS_WETH_SEPOLIA); + + const TO = "0xEA9eEca67682Cd9c6Ce3DdD1681049D7A897289F"; //address to send the tokens to + const VALUE = 1; //wei value, dont forget to multiply by decimals + + //send transfer and specify the type + const txReceipt = await myERC20.methods.transfer(TO, VALUE).send({ + from: wallet[0].address, + // highlight-next-line + type: 2, + }); + + console.log(txReceipt.transactionHash); + //=> 0x174bc88023be4af431fad1693a59f7a41135238510cdcd00f15f6409b5471d77 +} + +transfer(); +``` \ No newline at end of file diff --git a/docs/docs/guides/wallet/web3_modal_guide/_category_.yml b/docs/docs/guides/wallet/web3_modal_guide/_category_.yml index c89deac9d4b..0ce376f6e80 100644 --- a/docs/docs/guides/wallet/web3_modal_guide/_category_.yml +++ b/docs/docs/guides/wallet/web3_modal_guide/_category_.yml @@ -2,4 +2,4 @@ label: '📱 WalletConnect Tutorial' collapsible: true collapsed: true link: null -position: 4 +position: 6 diff --git a/docs/docs/guides/web3_plugin_guide/plugin_authors.md b/docs/docs/guides/web3_plugin_guide/plugin_authors.md index bde1e1e6558..4100882e67f 100644 --- a/docs/docs/guides/web3_plugin_guide/plugin_authors.md +++ b/docs/docs/guides/web3_plugin_guide/plugin_authors.md @@ -233,6 +233,73 @@ public link(parentContext: Web3Context) { } ``` +## Plugin Middleware + +Middleware allows plugins to intercept network interactions and inject custom logic. There are two types of plugin middleware: [request middleware](#request-middleware) and [transaction middleware](#transaction-middleware). In both cases, the middleware is implemented as a new class and registered with the plugin in the plugin's `link` method. Keep reading to learn how to add middleware to a plugin. + +### Request Middleware + +Request middleware allows plugins to modify RPC requests before they are sent to the network and modify RPC responses before they are returned to Web3.js for further internal processing. Request middleware must implement the [`RequestManagerMiddleware`](/api/web3-core/interface/RequestManagerMiddleware) interface, which specifies two functions: [`processRequest`](/api/web3-core/interface/RequestManagerMiddleware#processRequest) and [`processResponse`](/api/web3-core/interface/RequestManagerMiddleware#processResponse). Here is a simple example of request middleware that prints RPC requests and responses to the console: + +```ts +export class RequestMiddleware implements RequestManagerMiddleware { + public async processRequest( + request: JsonRpcPayload + ): Promise> { + const reqObj = { ...request } as JsonRpcPayload; + console.log("Request:", reqObj); + return Promise.resolve(reqObj as JsonRpcPayload); + } + + public async processResponse< + Method extends Web3APIMethod, + ResponseType = Web3APIReturnType + >( + response: JsonRpcResponse + ): Promise> { + const resObj = { ...response }; + console.log("Response:", resObj); + return Promise.resolve(resObj); + } +} +``` + +To add request middleware to a plugin, use the [`Web3RequestManager.setMiddleware`](/api/web3-core/class/Web3RequestManager#setMiddleware) method in the plugin's `link` method as demonstrated below: + +```ts +public link(parentContext: Web3Context): void { + parentContext.requestManager.setMiddleware(new RequestMiddleware()); + super.link(parentContext); +} +``` + +### Transaction Middleware + +Transaction middleware allows plugins to modify transaction data before it is sent to the network. Transaction middleware must implement the [`TransactionMiddleware`](/api/web3-eth/interface/TransactionMiddleware) interface, which specifies one function: [`processTransaction`](/api/web3-eth/interface/TransactionMiddleware#processTransaction). Here is a simple example of transaction middleware that prints transaction data to the console: + +```ts +export class TxnMiddleware implements TransactionMiddleware { + public async processTransaction( + transaction: TransactionMiddlewareData + ): Promise { + const txObj = { ...transaction }; + console.log("Transaction data:", txObj); + return Promise.resolve(txObj); + } +} +``` + +To add transaction middleware to a plugin, use the [`Web3Eth.setTransactionMiddleware`](/api/web3-eth/class/Web3Eth#setTransactionMiddleware) method in the plugin's `link` method as demonstrated below: + +```ts +public link(parentContext: Web3Context): void { + (parentContext as any).Web3Eth.setTransactionMiddleware( + new TxnMiddleware() + ); + super.link(parentContext); +} +``` + ## Setting Up Module Augmentation In order to provide type safety and IntelliSense for your plugin when it's registered by the user, you must [augment](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) the `Web3Context` module. In simpler terms, you will be making TypeScript aware that you are modifying the interface of the class `Web3Context`, and any class that extends it, to include the interface of your plugin (i.e. your plugin's added methods, properties, etc.). As a result, your plugin object will be accessible within a namespace of your choice, which will be available within any `Web3Context` object. diff --git a/packages/web3-errors/CHANGELOG.md b/packages/web3-errors/CHANGELOG.md index 7f9b132283b..3ed320c80a1 100644 --- a/packages/web3-errors/CHANGELOG.md +++ b/packages/web3-errors/CHANGELOG.md @@ -172,4 +172,10 @@ Documentation: - Added `InvalidIntegerError` error for fromWei and toWei (#7052) +## [1.2.1] + +### Fixed + +- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905) + ## [Unreleased] \ No newline at end of file diff --git a/packages/web3-errors/package.json b/packages/web3-errors/package.json index 1b8587c81b3..4d382b35716 100644 --- a/packages/web3-errors/package.json +++ b/packages/web3-errors/package.json @@ -1,6 +1,6 @@ { "name": "web3-errors", - "version": "1.2.0", + "version": "1.2.1", "description": "This package has web3 error classes", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -41,7 +41,7 @@ "test:integration": "jest --config=./test/integration/jest.config.js --passWithNoTests" }, "dependencies": { - "web3-types": "^1.6.0" + "web3-types": "^1.7.0" }, "devDependencies": { "@types/jest": "^28.1.6", diff --git a/packages/web3-errors/src/errors/contract_errors.ts b/packages/web3-errors/src/errors/contract_errors.ts index 3710d9f60f0..ccd2b7dd46a 100644 --- a/packages/web3-errors/src/errors/contract_errors.ts +++ b/packages/web3-errors/src/errors/contract_errors.ts @@ -159,7 +159,7 @@ export class Eip838ExecutionError extends Web3ContractError { // error.data, error.data.data or error.data.originalError.data (https://github.com/web3/web3.js/issues/4454#issuecomment-1485953455) if (typeof error.data === 'object') { let originalError: { data: string }; - if ('originalError' in error.data) { + if (error.data && 'originalError' in error.data) { originalError = error.data.originalError; } else { // Ganache has no `originalError` sub-object unlike others diff --git a/packages/web3-errors/test/unit/__snapshots__/errors.test.ts.snap b/packages/web3-errors/test/unit/__snapshots__/errors.test.ts.snap index 2eefbaa0814..22a863812e8 100644 --- a/packages/web3-errors/test/unit/__snapshots__/errors.test.ts.snap +++ b/packages/web3-errors/test/unit/__snapshots__/errors.test.ts.snap @@ -156,6 +156,17 @@ exports[`errors Eip838ExecutionError should get the data from error.data.origina } `; +exports[`errors Eip838ExecutionError should return correctly when data is undefined 1`] = ` +{ + "cause": undefined, + "code": undefined, + "data": undefined, + "innerError": undefined, + "message": "Error", + "name": "Eip838ExecutionError", +} +`; + exports[`errors InvalidConnectionError should have valid json structure 1`] = ` { "cause": undefined, diff --git a/packages/web3-errors/test/unit/errors.test.ts b/packages/web3-errors/test/unit/errors.test.ts index 7428cc9b6b3..0731f4dff37 100644 --- a/packages/web3-errors/test/unit/errors.test.ts +++ b/packages/web3-errors/test/unit/errors.test.ts @@ -329,6 +329,13 @@ describe('errors', () => { } as JsonRpcError).toJSON(), ).toMatchSnapshot(); }); + it('should return correctly when data is undefined', () => { + expect( + new contractErrors.Eip838ExecutionError({ + data: undefined, + } as JsonRpcError).toJSON(), + ).toMatchSnapshot(); + }); }); describe('ResponseError', () => { diff --git a/packages/web3-eth-abi/CHANGELOG.md b/packages/web3-eth-abi/CHANGELOG.md index 4a7f1fe8add..6d04047ddef 100644 --- a/packages/web3-eth-abi/CHANGELOG.md +++ b/packages/web3-eth-abi/CHANGELOG.md @@ -176,4 +176,10 @@ Documentation: - Dependencies updated +## [4.2.3] + +### Fixed + +- fix encodedata in EIP-712 (#7095) + ## [Unreleased] \ No newline at end of file diff --git a/packages/web3-eth-abi/package.json b/packages/web3-eth-abi/package.json index 4333ba616bb..7431abf8f23 100644 --- a/packages/web3-eth-abi/package.json +++ b/packages/web3-eth-abi/package.json @@ -1,6 +1,6 @@ { "name": "web3-eth-abi", - "version": "4.2.2", + "version": "4.2.3", "description": "Web3 module encode and decode EVM in/output.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -44,8 +44,8 @@ "dependencies": { "abitype": "0.7.1", "web3-errors": "^1.2.0", - "web3-types": "^1.6.0", - "web3-utils": "^4.3.0", + "web3-types": "^1.7.0", + "web3-utils": "^4.3.1", "web3-validator": "^2.0.6" }, "devDependencies": { diff --git a/packages/web3-eth-accounts/CHANGELOG.md b/packages/web3-eth-accounts/CHANGELOG.md index 30514ec972d..2b5d1c1ca6a 100644 --- a/packages/web3-eth-accounts/CHANGELOG.md +++ b/packages/web3-eth-accounts/CHANGELOG.md @@ -162,4 +162,10 @@ Documentation: - Dependencies updated +## [4.1.3] + +### Changed + +- baseTransaction method updated (#7095) + ## [Unreleased] \ No newline at end of file diff --git a/packages/web3-eth-accounts/package.json b/packages/web3-eth-accounts/package.json index dbd0a9fc881..aa25f89a5dd 100644 --- a/packages/web3-eth-accounts/package.json +++ b/packages/web3-eth-accounts/package.json @@ -1,6 +1,6 @@ { "name": "web3-eth-accounts", - "version": "4.1.2", + "version": "4.1.3", "description": "Package for managing Ethereum accounts and signing", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -61,9 +61,9 @@ "@ethereumjs/rlp": "^4.0.1", "crc-32": "^1.2.2", "ethereum-cryptography": "^2.0.0", - "web3-errors": "^1.1.4", - "web3-types": "^1.6.0", - "web3-utils": "^4.2.3", - "web3-validator": "^2.0.5" + "web3-errors": "^1.2.0", + "web3-types": "^1.7.0", + "web3-utils": "^4.3.1", + "web3-validator": "^2.0.6" } } diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index a1c4b6f35e5..bab02912320 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -386,10 +386,12 @@ Documentation: - `defaultReturnFormat` was added to all methods that have `ReturnType` param. (#6947) -## [Unreleased] +## [4.6.0] ### Added - `populateTransaction` was added to contract methods (#7124) - - Contract has `setTransactionMiddleware` and `getTransactionMiddleware` for automatically passing to `sentTransaction` for `deploy` and `send` functions (#7138) + +## [Unreleased] + diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index 81a3a9f2a3a..dcee58738b4 100644 --- a/packages/web3-eth-contract/package.json +++ b/packages/web3-eth-contract/package.json @@ -1,6 +1,6 @@ { "name": "web3-eth-contract", - "version": "4.5.0", + "version": "4.6.0", "description": "Web3 module to interact with Ethereum smart contracts.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -46,12 +46,12 @@ }, "dependencies": { "@ethereumjs/rlp": "^5.0.2", - "web3-core": "^4.4.0", + "web3-core": "^4.5.0", "web3-errors": "^1.2.0", - "web3-eth": "^4.7.0", - "web3-eth-abi": "^4.2.2", - "web3-types": "^1.6.0", - "web3-utils": "^4.3.0", + "web3-eth": "^4.8.1", + "web3-eth-abi": "^4.2.3", + "web3-types": "^1.7.0", + "web3-utils": "^4.3.1", "web3-validator": "^2.0.6" }, "devDependencies": { @@ -69,7 +69,7 @@ "prettier": "^2.7.1", "ts-jest": "^29.1.1", "typescript": "^4.7.4", - "web3-eth-accounts": "^4.1.2", - "web3-providers-ws": "^4.0.7" + "web3-eth-accounts": "^4.1.3", + "web3-providers-ws": "^4.0.8" } } diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index ba620044bde..6be4b4b5797 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -256,8 +256,17 @@ Documentation: - WebEth has `setTransactionMiddleware` and `getTransactionMiddleware` for automatically passing to `sentTransaction` (#7088) - `TransactionMiddleware` and `TransactionMiddleware` data types are exported (#7088) -## [Unreleased] +## [4.8.1] ### Fixed -- Fixed geth issue when running a new instance, transactions will index when there are no blocks created (#7098) \ No newline at end of file +- Fixed geth issue when running a new instance, transactions will index when there are no blocks created (#7098) + +## [4.8.2] + +### Fixed + +- Adds transaction property to be an empty list rather than undefined when no transactions are included in the block (#7151) +- Change method `getTransactionReceipt` to not be casted as `TransactionReceipt` to give proper return type (#7159) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3-eth/package.json b/packages/web3-eth/package.json index 336ed74df1e..75b35059356 100644 --- a/packages/web3-eth/package.json +++ b/packages/web3-eth/package.json @@ -1,6 +1,6 @@ { "name": "web3-eth", - "version": "4.8.0", + "version": "4.8.2", "description": "Web3 module to interact with the Ethereum blockchain and smart contracts.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -64,14 +64,14 @@ "dependencies": { "setimmediate": "^1.0.5", "web3-core": "^4.5.0", - "web3-errors": "^1.2.0", - "web3-eth-abi": "^4.2.2", - "web3-eth-accounts": "^4.1.2", + "web3-errors": "^1.2.1", + "web3-eth-abi": "^4.2.3", + "web3-eth-accounts": "^4.1.3", "web3-net": "^4.1.0", - "web3-providers-ws": "^4.0.7", + "web3-providers-ws": "^4.0.8", "web3-rpc-methods": "^1.3.0", "web3-types": "^1.7.0", - "web3-utils": "^4.3.0", + "web3-utils": "^4.3.1", "web3-validator": "^2.0.6" } } diff --git a/packages/web3-eth/src/rpc_method_wrappers.ts b/packages/web3-eth/src/rpc_method_wrappers.ts index 3a03afe0967..02fb9fbb173 100644 --- a/packages/web3-eth/src/rpc_method_wrappers.ts +++ b/packages/web3-eth/src/rpc_method_wrappers.ts @@ -286,11 +286,21 @@ export async function getBlock( hydrated, ); } - return format( + const res = format( blockSchema, response as unknown as Block, returnFormat ?? web3Context.defaultReturnFormat, ); + + if (!isNullish(res)) { + const result = { + ...res, + transactions: res.transactions ?? [], + } + return result; + } + + return res; } /** @@ -511,14 +521,13 @@ export async function getTransactionReceipt( } } - return isNullish(response) ? response : (format( transactionReceiptSchema, response as unknown as TransactionReceipt, returnFormat ?? web3Context.defaultReturnFormat, - ) as TransactionReceipt); + )); } /** diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block.ts index 4474bec4972..250f770bd64 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block.ts @@ -70,6 +70,10 @@ export const mockRpcResponseHydrated: Block = { ...mockRpcResponse, transactions: [hydratedTransaction, hydratedTransaction, hydratedTransaction], }; +export const noTransactionBlock: Block = { + ...mockRpcResponse, + transactions: [], +} /** * Array consists of: diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/get_block.test.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/get_block.test.ts index 778c6d4d000..365fb09d9ec 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/get_block.test.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/get_block.test.ts @@ -28,7 +28,7 @@ import { isBytes, isNullish } from 'web3-validator'; import { ethRpcMethods } from 'web3-rpc-methods'; import { getBlock } from '../../../src/rpc_method_wrappers'; -import { mockRpcResponse, mockRpcResponseHydrated, testData } from './fixtures/get_block'; +import { mockRpcResponse, mockRpcResponseHydrated, testData, noTransactionBlock } from './fixtures/get_block'; import { blockSchema } from '../../../src/schemas'; jest.mock('web3-rpc-methods'); @@ -84,4 +84,31 @@ describe('getBlock', () => { expect(result).toStrictEqual(expectedFormattedResult); }, ); + + it.each(testData)( + `should format the block to include transactions as an empty array if no transactions are present\nTitle: %s\nInput parameters: %s\n`, + async (_, inputParameters) => { + const [inputBlock] = inputParameters; + const expectedReturnFormat = { number: FMT_NUMBER.STR, bytes: FMT_BYTES.UINT8ARRAY }; + const expectedMockRpcResponse = noTransactionBlock; + // TODO: Fix format to default have a default in oneOf if no schema is matched + const formattedResult = format( + blockSchema, + expectedMockRpcResponse, + expectedReturnFormat, + ); + const expectedFormattedResult = {...formattedResult, + transactions: [] + }; + const inputBlockIsBytes = isBytes(inputBlock as Bytes); + ( + (inputBlockIsBytes + ? ethRpcMethods.getBlockByHash + : ethRpcMethods.getBlockByNumber) as jest.Mock + ).mockResolvedValueOnce(expectedMockRpcResponse); + + const result = await getBlock(web3Context, ...inputParameters, expectedReturnFormat); + expect(result).toStrictEqual(expectedFormattedResult); + }, + ); }); diff --git a/packages/web3-providers-ws/CHANGELOG.md b/packages/web3-providers-ws/CHANGELOG.md index 8648c09c9d3..3dbc8c54694 100644 --- a/packages/web3-providers-ws/CHANGELOG.md +++ b/packages/web3-providers-ws/CHANGELOG.md @@ -122,11 +122,16 @@ Documentation: - Dependencies updated - ## [4.0.7] ### Fixed - Fixed bug in chunks processing logic (#6496) +## [4.0.8] + +### Changed + +- Update dependancies (#7109) + ## [Unreleased] \ No newline at end of file diff --git a/packages/web3-providers-ws/package.json b/packages/web3-providers-ws/package.json index 41a37fba435..49595cc21df 100644 --- a/packages/web3-providers-ws/package.json +++ b/packages/web3-providers-ws/package.json @@ -1,6 +1,6 @@ { "name": "web3-providers-ws", - "version": "4.0.7", + "version": "4.0.8", "description": "Websocket provider for Web3 4.x.x", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -64,9 +64,9 @@ "dependencies": { "@types/ws": "8.5.3", "isomorphic-ws": "^5.0.0", - "web3-errors": "^1.1.3", - "web3-types": "^1.3.0", - "web3-utils": "^4.0.7", + "web3-errors": "^1.2.0", + "web3-types": "^1.7.0", + "web3-utils": "^4.3.1", "ws": "^8.17.1" } } diff --git a/packages/web3-rpc-providers/CHANGELOG.md b/packages/web3-rpc-providers/CHANGELOG.md index 78d7c02f440..d9fe3235240 100644 --- a/packages/web3-rpc-providers/CHANGELOG.md +++ b/packages/web3-rpc-providers/CHANGELOG.md @@ -37,10 +37,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.0.0.rc.0] -#### Added +### Added - RC release -## [Unreleased] +## [1.0.0.rc.1] + + ### Added + - When error is returned with code 429, throw rate limit error (#7102) - - Change request return type `Promise` to `Promise>` (#7102) \ No newline at end of file + + ### Changed + + - Change request return type `Promise` to `Promise>` (#7102) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3-rpc-providers/package.json b/packages/web3-rpc-providers/package.json index 8aed22fe547..606ced0ed22 100644 --- a/packages/web3-rpc-providers/package.json +++ b/packages/web3-rpc-providers/package.json @@ -1,6 +1,6 @@ { "name": "web3-rpc-providers", - "version": "1.0.0-rc.0", + "version": "1.0.0-rc.1", "description": "Web3 Providers package", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -58,9 +58,9 @@ "dependencies": { "web3-errors": "^1.2.0", "web3-providers-http": "^4.1.0", - "web3-providers-ws": "^4.0.7", - "web3-validator": "^2.0.6", + "web3-providers-ws": "^4.0.8", "web3-types": "^1.7.0", - "web3-utils": "^4.3.0" + "web3-utils": "^4.3.1", + "web3-validator": "^2.0.6" } } diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index 20474ce0ab3..8f25c4c6b20 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -228,6 +228,10 @@ Documentation: - `toWei` support numbers in scientific notation (#6908) - `toWei` and `fromWei` trims according to ether unit successfuly (#7044) -## [Unreleased] +## [4.3.1] + +### Fixed - `_sendPendingRequests` will catch unhandled errors from `_sendToSocket` (#6968) + +## [Unreleased] diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index c07e9b85821..c9c6c6a4ad8 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -1,7 +1,7 @@ { "name": "web3-utils", "sideEffects": false, - "version": "4.3.0", + "version": "4.3.1", "description": "Collection of utility functions used in web3.js.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -66,7 +66,7 @@ "ethereum-cryptography": "^2.0.0", "eventemitter3": "^5.0.1", "web3-errors": "^1.2.0", - "web3-types": "^1.6.0", + "web3-types": "^1.7.0", "web3-validator": "^2.0.6" } } diff --git a/packages/web3/CHANGELOG.md b/packages/web3/CHANGELOG.md index d95a14cc116..e8b2d5c705a 100644 --- a/packages/web3/CHANGELOG.md +++ b/packages/web3/CHANGELOG.md @@ -381,10 +381,59 @@ Documentation: - `getName` reverse resolution -## [Unreleased] + +## [4.11.0] + +### Fixed + +#### web3-eth-abi + +- fix encodedata in EIP-712 (#7095) + +#### web3-utils + +- `_sendPendingRequests` will catch unhandled errors from `_sendToSocket` (#6968) + +#### web3-eth + +- Fixed geth issue when running a new instance, transactions will index when there are no blocks created (#7098) + +### Changed + +#### web3-eth-accounts + +- baseTransaction method updated (#7095) + +#### web3-providers-ws + +- Update dependancies (#7109) ### Added +#### web3-eth-contract + +- `populateTransaction` was added to contract methods (#7124) +- Contract has `setTransactionMiddleware` and `getTransactionMiddleware` for automatically passing to `sentTransaction` for `deploy` and `send` functions (#7138) + #### web3 - `web3.eth.Contract` will get transaction middleware and use it, if `web3.eth` has transaction middleware. (#7138) + +## [4.11.1] + +### Fixed + +#### web3-errors + +- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905) + +#### web3-eth + +- Adds transaction property to be an empty list rather than undefined when no transactions are included in the block (#7151) +- Change method `getTransactionReceipt` to not be casted as `TransactionReceipt` to give proper return type (#7159) + +#### web3 + +- Remove redundant constructor of contractBuilder (#7150) + +## [Unreleased] \ No newline at end of file diff --git a/packages/web3/package.json b/packages/web3/package.json index 5d05fa85923..2b680517e80 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -1,6 +1,6 @@ { "name": "web3", - "version": "4.10.0", + "version": "4.11.1", "description": "Ethereum JavaScript API", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -87,21 +87,21 @@ }, "dependencies": { "web3-core": "^4.5.0", - "web3-errors": "^1.2.0", - "web3-eth": "^4.8.0", - "web3-eth-abi": "^4.2.2", - "web3-eth-accounts": "^4.1.2", - "web3-eth-contract": "^4.5.0", + "web3-errors": "^1.2.1", + "web3-eth": "^4.8.2", + "web3-eth-abi": "^4.2.3", + "web3-eth-accounts": "^4.1.3", + "web3-eth-contract": "^4.6.0", "web3-eth-ens": "^4.4.0", "web3-eth-iban": "^4.0.7", "web3-eth-personal": "^4.0.8", "web3-net": "^4.1.0", "web3-providers-http": "^4.1.0", - "web3-providers-ws": "^4.0.7", + "web3-providers-ws": "^4.0.8", "web3-rpc-methods": "^1.3.0", - "web3-rpc-providers": "^1.0.0-rc.0", + "web3-rpc-providers": "^1.0.0-rc.1", "web3-types": "^1.7.0", - "web3-utils": "^4.3.0", + "web3-utils": "^4.3.1", "web3-validator": "^2.0.6" } } diff --git a/packages/web3/src/version.ts b/packages/web3/src/version.ts index 8b07e0d3591..268f69fed23 100644 --- a/packages/web3/src/version.ts +++ b/packages/web3/src/version.ts @@ -1 +1 @@ -/* eslint-disable header/header */ export const Web3PkgInfo = { version: '4.10.0' }; +/* eslint-disable header/header */ export const Web3PkgInfo = { version: '4.11.1' }; diff --git a/packages/web3/src/web3.ts b/packages/web3/src/web3.ts index 9b231e7c6eb..c3362364f9a 100644 --- a/packages/web3/src/web3.ts +++ b/packages/web3/src/web3.ts @@ -137,12 +137,6 @@ export class Web3< optionsOrContextOrReturnFormat?: ContractInitOptions, contextOrReturnFormat?: Web3Context | DataFormat, ); - public constructor( - jsonInterface: Abi, - addressOrOptionsOrContext?: Address | ContractInitOptions, - optionsOrContextOrReturnFormat?: ContractInitOptions, - contextOrReturnFormat?: Web3Context | DataFormat, - ); public constructor( jsonInterface: Abi, addressOrOptionsOrContext?: Address | ContractInitOptions, diff --git a/tools/web3-plugin-example/CHANGELOG.md b/tools/web3-plugin-example/CHANGELOG.md index 6762e7f8b1b..76e9b8f8b96 100644 --- a/tools/web3-plugin-example/CHANGELOG.md +++ b/tools/web3-plugin-example/CHANGELOG.md @@ -92,4 +92,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Transaction middleware (#7088) +## [1.1.1] + +### Changed + +- Dependencies updated + ## [Unreleased] \ No newline at end of file diff --git a/tools/web3-plugin-example/package.json b/tools/web3-plugin-example/package.json index c2463255ac8..b44886d5f37 100644 --- a/tools/web3-plugin-example/package.json +++ b/tools/web3-plugin-example/package.json @@ -1,6 +1,6 @@ { "name": "web3-plugin-example", - "version": "1.1.0", + "version": "1.1.1", "description": "Example implementations of Web3.js' 4.x plugin system", "repository": "https://github.com/ChainSafe/web3.js", "engines": { @@ -45,12 +45,12 @@ "prettier": "^2.7.1", "ts-jest": "^29.1.1", "typescript": "^4.7.4", - "web3": "^4.10.0", + "web3": "^4.11.0", "web3-core": "^4.5.0", - "web3-eth-abi": "^4.2.2", - "web3-eth-contract": "^4.5.0", + "web3-eth-abi": "^4.2.3", + "web3-eth-contract": "^4.6.0", "web3-types": "^1.7.0", - "web3-utils": "^4.3.0" + "web3-utils": "^4.3.1" }, "peerDependencies": { "web3-core": ">= 4.1.1 < 5",