diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 116e5513a02..ff423d3e49c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,4 +2,4 @@ # https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners # Automatically assigns members of the web3.js team to new pending PRs as reviewers -* @avkos @jdevcs @luu-alex @Muhammad-Altabba @krzysu @danforbes +* @jdevcs @AlexeyKrasnoperov diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 9ebc3e40d6c..cccc9fc9341 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -11,36 +11,36 @@ appearance, race, religion, or sexual identity and orientation. ## Our Standards -Examples of behaviour that contributes to creating a positive environment +Examples of behavior that contributes to creating a positive environment include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members -Examples of unacceptable behaviour by participants include: +Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable -behaviour and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behaviour. +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviours that they deem inappropriate, +permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope @@ -73,4 +73,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq \ No newline at end of file +https://www.contributor-covenant.org/faq diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2702e75d4d2..ad7ab9572d2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -8,35 +8,45 @@ If you face any issues while contributing or want any type of support, we encour ## Prerequisites -- [NodeJS](https://nodejs.org/) (LTS) -- [Yarn](https://yarnpkg.com/) +- [NodeJS](https://nodejs.org/) (LTS) +- [Yarn](https://yarnpkg.com/) ## Contributing to the docs +> [!NOTE] +> Contributions that only address relatively minor typographical errors are not accepted. If you believe you have identified an important typographical error that should be addressed, [please open an Issue](https://github.com/web3/web3.js/issues/new?assignees=&labels=Documentation&projects=&template=issue-template.md&title=[Typo]). + 1. **Fork the docs:** Start by forking our repository to your GitHub account. 2. **Clone the repo:** Clone the forked repository to your local machine using the following command: + ```bash git clone https://github.com/your-username/web3.js.git ``` + 3. **Create a Branch:** Create a new branch for your changes with a descriptive name. - **NOTE: The branch name must include the issue number (if there is no issue created for your contribution, please create one).** + **NOTE: The branch name must include the issue number (if there is no issue created for your contribution, please create one).** + ```bash git checkout -b issue-name-1234 ``` + 4. **Navigate to the docs folder:** `cd web3.js/docs/docs` -5. **Install dependencies:** +5. **Install dependencies:** + ```bash yarn ``` + 6. **Make your changes:**... 7. Check changes in the local environment: Run the command `yarn start` and you'll see a local environment in `localhost:3000` with the documents. -8. **Commit your changes:** `git add .` and `git commit -m 'descriptive msg'` +8. **Commit your changes:** `git add .` and `git commit -m 'descriptive msg'` 9. **Push your changes:** + ```bash git push origin branch-name ``` @@ -96,4 +106,3 @@ Emergency releases are allowed to shorten waiting periods depending on the sever There is precedent set for this in the 1.2.6 release (see [#3351](https://github.com/ethereum/web3.js/pull/3351)), where the consensus view was to make the smallest change necessary to address the emergency while waiving the `rc` process (meaning many existing additions to master were excluded). This topic is under further org-wide discussion at [ethereum/js-organization#6](https://github.com/ethereum/js-organization/issues/6). - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7ad07339c5c..b7a527fb7d8 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -11,23 +11,24 @@ Fixes #(issue) -- [ ] Bug fix (non-breaking change which fixes an issue) -- [ ] New feature (non-breaking change which adds functionality) -- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] Documentation (changes that only address relatively minor typographical errors are not accepted) ## Checklist: -- [ ] I have selected the correct base branch. -- [ ] I have performed a self-review of my own code. -- [ ] I have commented my code, particularly in hard-to-understand areas. -- [ ] I have made corresponding changes to the documentation. -- [ ] My changes generate no new warnings. -- [ ] Any dependent changes have been merged and published in downstream modules. -- [ ] I ran `npm run lint` with success and extended the tests and types if necessary. -- [ ] I ran `npm run test:unit` with success. -- [ ] I ran `npm run test:coverage` and my test cases cover all the lines and branches of the added code. -- [ ] I ran `npm run build` and tested `dist/web3.min.js` in a browser. -- [ ] I have tested my code on the live network. -- [ ] I have checked the Deploy Preview and it looks correct. -- [ ] I have updated the `CHANGELOG.md` file in the root folder. -- [ ] I have linked Issue(s) with this PR in "Linked Issues" menu. +- [ ] I have selected the correct base branch. +- [ ] I have performed a self-review of my own code. +- [ ] I have commented my code, particularly in hard-to-understand areas. +- [ ] I have made corresponding changes to the documentation. +- [ ] My changes generate no new warnings. +- [ ] Any dependent changes have been merged and published in downstream modules. +- [ ] I ran `npm run lint` with success and extended the tests and types if necessary. +- [ ] I ran `npm run test:unit` with success. +- [ ] I ran `npm run test:coverage` and my test cases cover all the lines and branches of the added code. +- [ ] I ran `npm run build` and tested `dist/web3.min.js` in a browser. +- [ ] I have tested my code on the live network. +- [ ] I have checked the Deploy Preview and it looks correct. +- [ ] I have updated the `CHANGELOG.md` file in the root folder. +- [ ] I have linked Issue(s) with this PR in "Linked Issues" menu. diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ea32551380..13aa1bcb9eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2501,7 +2501,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f #### web3-validator - The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981) -- `browser` entry point that was pointing to an non-existing bundle file was removed from `package.json` (#7015) +- `browser` entry point that was pointing to a non-existing bundle file was removed from `package.json` (#7015) #### web3-core @@ -2792,17 +2792,13 @@ If there are any bugs, improvements, optimizations or any new feature proposal f - `FilterParams` type added (#7353) -#### web3-account-abstraction - -- RC release - ### Fixed #### web3-eth-contracts - Fix Contract methods input param type any[] (#7340) -## [Unreleased] +## [4.16.0] ### Fixed @@ -2813,3 +2809,64 @@ If there are any bugs, improvements, optimizations or any new feature proposal f #### web3-utils - Make `fromWei` return "0" when input is `0` (#7387) + +### Removed + +#### web3-eth-accounts + +- Move signature related types to web3-types. Re-export them for backwards compatibility. (#7374) + +### Added + +#### web3-types + +- Add signature related types. (#7374) +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-eth-accounts + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3 + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-core + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-account-abstraction + +- RC release + +#### web3-errors + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-eth + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-eth-contract + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-rpc-providers + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-utils + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-eth-abi + +- Updated Typescript version 4 -> 5 (#7272) + +## [Unreleased] + +### Added + +#### web3-validator + +- Add web3-validator dist path for react-native builds (#7416) diff --git a/README.md b/README.md index 3284ef04f23..1caa1dd5e55 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ # Web3.js +### Web3.js libraries are being sunset on March 4th, 2025. For migration guides and more details please refer to [Chainsafe blog](https://blog.chainsafe.io/web3-js-sunset/) + [![Dependency Status][downloads-image]][npm-url] ![Unit Test Coverage](https://img.shields.io/codecov/c/github/web3/web3.js/4.x?label=unit%20test%20coverage) ![Commit Activity](https://img.shields.io/github/commit-activity/m/web3/web3.js/4.x?label=commit%20activity%20on%204.x) ![Contributors](https://img.shields.io/github/contributors/web3/web3.js?label=contributors%20on%20all%20branches) diff --git a/docs/docs/guides/01_getting_started/introduction.md b/docs/docs/guides/01_getting_started/introduction.md index d8838984205..bfd5e6465ba 100644 --- a/docs/docs/guides/01_getting_started/introduction.md +++ b/docs/docs/guides/01_getting_started/introduction.md @@ -6,6 +6,12 @@ sidebar_label: Introduction # Introduction +:::warning + +Web3.js libraries are being sunset on March 4th, 2025. For migration guides and more details please refer to [Chainsafe blog](https://blog.chainsafe.io/web3-js-sunset/) + +::: + Web3.js is a robust and flexible collection of **TypeScript and JavaScript** libraries that allows developers to interact with local or remote [Ethereum](https://ethereum.org/en/) nodes (or **any EVM-compatible blockchain**) over **HTTP, IPC or WebSocket** connections. It is a powerful and efficient toolkit for crafting applications within the Ethereum ecosystem and beyond. This documentation is the entrypoint to Web3.js for developers. It covers [basic](/guides/getting_started/quickstart) and [advanced](/guides/dapps/lightweight-dapp) usage with examples, and includes comprehensive [API documentation](/api) as well as guides for common tasks, like [upgrading](/guides/web3_upgrade_guide) from older versions. diff --git a/docs/docs/guides/09_web3_config/index.md b/docs/docs/guides/09_web3_config/index.md index 3642aad951d..ff1576edfc3 100644 --- a/docs/docs/guides/09_web3_config/index.md +++ b/docs/docs/guides/09_web3_config/index.md @@ -6,7 +6,7 @@ title: 'Web3.js Config Guide' ## Configuration parameters -There is list of configuration params that can be set for modifying behavior of different functions in web3.js packages. Following is list of configuration options with details: +There is list of configuration parameters that can be set to modify the behavior of different functions in web3.js packages. Following is list of configuration options with details: - [handleRevert](/guides/web3_config/#handlerevert) - [defaultAccount](/guides/web3_config/#defaultaccount) @@ -33,7 +33,7 @@ There is list of configuration params that can be set for modifying behavior of ## Global level Config -There is option of modifying any of above-mentioned configuration parameter at global level when instantiating Web3, and it will be available to all packages. +It is possible to modify any of the above-mentioned configuration parameter at the global level when instantiating a `Web3` object, and it will be available to all packages. ```ts import { Web3 } from 'web3'; diff --git a/docs/docs/guides/10_web3_eth/eth.md b/docs/docs/guides/10_web3_eth/eth.md index 5b97adea208..bc63995118f 100644 --- a/docs/docs/guides/10_web3_eth/eth.md +++ b/docs/docs/guides/10_web3_eth/eth.md @@ -674,7 +674,7 @@ async function test() { ## Conclusion -In this tutorial, we learned how to use different methods provied by the `web3-eth` package. +In this tutorial, we learned how to use different methods provided by the `web3-eth` package. With this knowledge, you can start experimenting with the Ethereum blockchain. Keep in mind that this is just the beginning, and there is a lot more to learn about Ethereum and web3.js. So keep exploring and building, and have fun! diff --git a/docs/docs/guides/12_web3_utils_module/index.md b/docs/docs/guides/12_web3_utils_module/index.md index 8a55f7bfe85..7833ffd8a1b 100644 --- a/docs/docs/guides/12_web3_utils_module/index.md +++ b/docs/docs/guides/12_web3_utils_module/index.md @@ -199,7 +199,7 @@ console.log(web3.utils.soliditySha3({ type: 'string', value: 'hello web3' })); console.log(web3.utils.toChecksumAddress('0xa3286628134bad128faeef82f44e99aa64085c94')); // 0xA3286628134baD128faeef82F44e99AA64085C94 -// passing an wrong address +// passing a wrong address console.log(web3.utils.toChecksumAddress('0xa3286628134bad128faeef82f44e99aa64085c9')); // InvalidAddressError: Invalid value given "0xa286628134bad128faeef82f44e99aa64085c94". Error: invalid ethereum address. ``` @@ -246,7 +246,7 @@ console.log(web3.utils.compareBlockNumbers(2, 2)); ### Formatting -The [`format` function](/api/web3-utils/function/format) in the `web3-utils` package is used to convert data between equivalent formats. For example, bytes that are represented as a [`Uint8Array` type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) can be formatted as a hexademical string (e.g. `"0xdd"`) or primitive JavaScript [`Number` types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) can be formatted as [`BigInt` types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt). The `format` function expects two required parameters, `schema` and `data`, and accepts a third optional parameter, `returnFormat`. The `schema` parameter is used to describe how the data should be interpreted. The `data` parameter represents the data that is to be formatted. The [`returnFormat` parameter](#return-formats) specifies how the data should be formatted. +The [`format` function](/api/web3-utils/function/format) in the `web3-utils` package is used to convert data between equivalent formats. For example, bytes that are represented as a [`Uint8Array` type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) can be formatted as a hexadecimal string (e.g. `"0xdd"`) or primitive JavaScript [`Number` types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) can be formatted as [`BigInt` types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt). The `format` function expects two required parameters, `schema` and `data`, and accepts a third optional parameter, `returnFormat`. The `schema` parameter is used to describe how the data should be interpreted. The `data` parameter represents the data that is to be formatted. The [`returnFormat` parameter](#return-formats) specifies how the data should be formatted. Here are some example that demonstrate the use of the `format` function: diff --git a/docs/docs/guides/17_migration_ethers/index.md b/docs/docs/guides/17_migration_ethers/index.md new file mode 100644 index 00000000000..33aaad48f3e --- /dev/null +++ b/docs/docs/guides/17_migration_ethers/index.md @@ -0,0 +1,345 @@ +--- +sidebar_label: 'πŸ”„ Migration to ethers.js' +title: 'Migration from Web3.js to Ethers.js' +position: 17 +--- + +This guide will help you migrate from web3.js to ethers.js for interacting with the Ethereum blockchain. The guide covers ethers.js v6, providing code examples for both libraries. + +### Installation + +To begin migrating from Web3.js to ethers.js, first install the ethers.js package: + +``` +npm install ethers@6 + +``` + +### Providers Initialization + +When migrating from Web3.js to ethers.js, the first step is to update how you connect to the Ethereum network. Both libraries use providers, but their initialization differs. + +```typescript +import { Web3 } from 'web3'; + +// private RPC endpoint +const web3 = new Web3(providerURL); + +const blockNumber = await web3.eth.getBlockNumber(); +console.log(blockNumber); +``` + +To migrate this to ethers.js, you'll need to replace it with JsonRpcProvider. Note that ethers.js separates provider types more explicitly: + +```typescript +import { ethers } from 'ethers'; + +// ethers.js v6 +const provider = new ethers.JsonRpcProvider(providerURL); + +const blockNumber = await provider.getBlockNumber(); +console.log(blockNumber); +``` + +### Browser-injected Provider + +When migrating browser wallet connections, you'll need to update how you handle the injected provider (like MetaMask). Here's your existing Web3.js code: + +```typescript +const web3 = new Web3(window.ethereum); +``` + +In ethers.js v6, you'll need to use the BrowserProvider class instead. This provider is specifically designed for browser environments: + +```typescript +// in v6 +const provider = new ethers.BrowserProvider(window.ethereum); +``` + +### Wallets and Accounts - Generate Private Key + +If your code generates private keys with Web3.js, here's how to migrate that functionality. Your existing Web3.js code: + +```typescript +// this would generate a private key similar to: +// '0x286f65c4191759fc5c7e6083b8c275ac2238cc7abb5915bd8c905ae4404215c9' +// (Be sure to store it encrypted in a safe place) +const privateKey = web3.eth.accounts.create().privateKey; +``` + +To achieve the same in ethers.js, use the `Wallet.createRandom()` method: + +```typescript +// this would generate a private key similar to: +// '0x286f65c4191759fc5c7e6083b8c275ac2238cc7abb5915bd8c905ae4404215c9' +// (Be sure to store it encrypted in a safe place) +const privateKey = ethers.Wallet.createRandom().privateKey; +``` + +### Wallets and Accounts - Create a wallet + +When migrating wallet creation code, you'll need to change how accounts are added to wallets. Your existing Web3.js code using `wallet.add()`: + +```typescript +const web3 = new Web3(); +const wallet = web3.eth.accounts.wallet.add( + // you can generate a private key using web3.eth.accounts.create().privateKey + privateKey, +); + +// outputs: 0x6f7D735dFB514AA1778E8D97EaCE72BfECE71865 +console.log(wallet[0].address); +``` + +In ethers.js, wallet creation uses the Wallet constructor: + +```typescript +const wallet = new ethers.Wallet( + // A private key that you might had generated with: + ethers.Wallet.createRandom().privateKey, + // or explicitly given privateKey +); + +// outputs: 0x6f7D735dFB514AA1778E8D97EaCE72BfECE71865 +console.log(wallet.address); +``` + +### Get Signer account + +When migrating code that gets the current account, you'll need to change from Web3.js's getAccounts(): + +```typescript +const account = (await web3.eth.getAccounts())[0]; +``` + +To ethers.js's getSigner() method, which returns a signer object instead of just an address: + +```typescript +const signer = await provider.getSigner(); +``` + +### Signing + +When migrating message signing functionality, you'll need to update from Web3.js's sign methods: + +```typescript +// Sign with web3.js, using a private key: +const signature = web3.eth.accounts.sign('Some data', privateKey).signature; + +// Sign using an account managed by the connected provider +const signature = await web3.eth.sign( + web3.utils.utf8ToHex('Some data'), // data to be signed (4.x only supports Hex Strings) + '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4', // the address +); +``` + +In ethers.js, signing is simplified using the signMessage method: + +```typescript +const signer = new ethers.Wallet(privateKey); +const signature = await signer.signMessage('Some data'); +``` + +## Signing and Sending Transactions + +### Sending Transactions + +When migrating transaction sending code, you'll need to update how transactions are signed and sent. Your existing Web3.js code where transactions are signed using an unlocked or added account: + +```typescript +const web3 = new Web3(url); + +// Add wallet to be used as a signer +const wallet = web3.eth.accounts.wallet.add(givenPrivateKey); +const account = wallet[0].address; + +const tx = await web3.eth.sendTransaction({ + from: account, + to: '0x92d3267215Ec56542b985473E73C8417403B15ac', + value: web3.utils.toWei('0.00000000001', 'ether'), +}); +console.log(tx); +``` + +In ethers.js, transactions are sent using a signer instance, which combines the private key and provider: + +```typescript +const signer = new ethers.Wallet(privateKey, provider); + +const tx = await signer.sendTransaction({ + to: '0x92d3267215Ec56542b985473E73C8417403B15ac', + value: ethers.parseUnits('0.001', 'ether'), +}); +console.log(tx); +``` + +### Sending a Signed Transaction + +When migrating code that separates transaction signing and broadcasting, you'll need to update from Web3.js's two-step process: + +```typescript +const transaction = { + from: senderPublicAddress, + to: receiverPublicAddress, + value: 1, + gas: 21000, +}; + +const signedTransaction = await web3.eth.accounts.signTransaction(transaction, privateKey); + +const tx = await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction); + +console.log(tx); +``` + +In ethers.js, you can broadcast a pre-signed transaction using the provider's broadcastTransaction method: + +```typescript +await provider.broadcastTransaction(signedTx); +``` + +## Contracts + +### Contract Deployment + +When migrating contract deployment code, you'll need to update from Web3.js's deploy and send pattern: + +```typescript +const contract = new web3.eth.Contract(abi); +const deployTx = await contract + .deploy({ + data: bytecode, + arguments: ['constructor param'], + }) + .send({ + from: '0x12598d2Fd88B420ED571beFDA8dD112624B5E730', + gas: '1000000', + }); + +console.log('contract address', deployTx.options.address); +``` + +In ethers.js, contract deployment uses the ContractFactory class: + +```typescript +const signer = await provider.getSigner(); +const factory = new ethers.ContractFactory(abi, bytecode, signer); +const contract = await factory.deploy('constructor param'); +console.log('contract address', contract.address); + +// wait for contract creation transaction to be mined +await contract.deployTransaction.wait(); +``` + +### Contract Method Calls + +When migrating contract method calls, you'll need to update from Web3.js's methods object pattern: + +```typescript +const contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); + +// For read operations +const result = await contract.methods.someFunction().call(); + +// For write operations +const tx = await contract.methods.someFunction().send(); +``` + +In ethers.js, contract methods are called directly as functions: + +```typescript +const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, provider); +const result = await contract.someFunction(); +``` + +### Contract Events + +When migrating event handling code, you'll need to update from Web3.js's events interface: + +```typescript +const event = contract.events.SomeEvent({ + filter: { val: 100 }, + fromBlock: 0, +}); + +event.on('data', resolve); +event.on('error', reject); +``` + +In ethers.js, event listening is : + +```typescript +contract.on('SomeEvent', (arg1, arg2, event) => { + // event handling +}); +``` + +### Gas Estimation + +When migrating gas estimation code, you'll need to update from Web3.js's estimateGas method: + +```typescript +const gasAmount = await contract.methods.myMethod(123).estimateGas({ + from: transactionSenderAddress, +}); +``` + +In ethers.js, gas estimation is made through a direct method call: + +```typescript +const gasEstimate = await contract.myMethod.estimateGas(123); +``` + +## Utility methods + +### Hashing + +When migrating code that computes Keccak-256 hashes, you'll need to update from Web3.js's utility methods: + +```typescript +// computes the Keccak-256 hash of the input and returns a hexstring +const hash1 = web3.utils.sha3('hello world'); + +// alternative keccak256 method with broader input support +const hash2 = web3.utils.keccak256('hello world'); +``` + +In ethers.js, hashing requires explicit conversion of strings to bytes: + +```typescript +import { keccak256, toUtf8Bytes } from 'ethers'; + +const message = 'Hello, World!'; +const messageBytes = toUtf8Bytes(message); +const hash = keccak256(messageBytes); +``` + +### Ether Unit Conversion + +When migrating code that converts between ether units, you'll need to update from Web3.js's fromWei and toWei methods: + +```typescript +// Convert Wei to Ether +const fromWeiToEther = web3.utils.fromWei('1000000000000000000', 'ether'); +// outputs: 1 +console.log(fromWeiToEther); + +// Convert Ether to Wei +const fromEtherToWei = web3.utils.toWei('1.0', 'ether'); +// outputs: 1000000000000000000 +console.log(fromEtherToWei); +``` + +In ethers.js, use formatEther and parseEther for common ether conversions: + +```typescript +// Convert Wei to Ether +const fromWeiToEther = ethers.formatEther('1000000000000000000'); +// outputs: 1.0 +console.log(fromWeiToEther); + +// Convert Ether to Wei +const fromEtherToWei = ethers.parseEther('1.0'); +// outputs: 1000000000000000000n +console.log(fromEtherToWei); +``` diff --git a/docs/docs/guides/17_migration_from_other_libs/index.md b/docs/docs/guides/17_migration_from_other_libs/index.md deleted file mode 100644 index 78e1f48d20c..00000000000 --- a/docs/docs/guides/17_migration_from_other_libs/index.md +++ /dev/null @@ -1,465 +0,0 @@ ---- -sidebar_label: 'πŸ”„ Migration from ethers.js' -title: 'Migration from ethers.js' -position: 17 ---- - -Follow this guide, if you're currently using the ethers.js library to interact with the Ethereum blockchain and want to migrate to web3.js. This guide is for ethers v5 and v6. And, if there are differences, code for both would be provided. And, if you find something missing, or worth adding, feel free to open a PR, please. - -However, migrating from a library to another would usually need careful changes. But, ethers.js have lots of similarities with web3.js and migration would usually be easy and straightforward. However, you still need to check your code for possible tweaks as needed. - -## Installation - -First, install the latest version of web3.js: - -```bash -npm install web3 -``` - -## Providers - -### Initialization and Calling RPC Methods - -With ethers.js, you would get the last block number from a provider like this: - -```typescript -import { ethers } from 'ethers'; - -// in v5: -const provider = new ethers.providers.JsonRpcProvider(url); - -// in v6: -const provider = new ethers.JsonRpcProvider(url); - -const blockNumber = provider.getBlockNumber(); - -// outputs something like: 18561956 -blockNumber.then(console.log); -``` - -With web3.js, you would get the last block number from a provider like this: - -```typescript -import { Web3 } from 'web3'; - -const web3 = new Web3(url); -const blockNumber = web3.eth.getBlockNumber(); - -// outputs something like: 18561956n -blockNumber.then(console.log); -``` - -:::tip -πŸ“ web3.js uses `bigint` as the default type for all big numbers returned. For, this you see above the blocknumber has the `n` at its end (`18561956n`). However, you can change the returned type by passing an optional parameter like: -::: - -```ts title='BigInt Tip' -import { Web3, DEFAULT_RETURN_FORMAT, FMT_NUMBER } from 'web3'; - -const blockNumber = web3.eth.getBlockNumber({ - ...DEFAULT_RETURN_FORMAT, - number: FMT_NUMBER.HEX, // to get the block number in hex format -}); -// outputs something like: 0x11B3BA4 -blockNumber.then(console.log); - -const blockNumber = web3.eth.getBlockNumber({ - ...DEFAULT_RETURN_FORMAT, - number: FMT_NUMBER.STR, // to get the block number as a string -}); -// the value would like: '18561956' -blockNumber.then(console.log); -``` - -### Use browser-injected provider - -With ethers.js: - -```typescript -// in v5 -const provider = new ethers.providers.Web3Provider(window.ethereum); - -// in v6 -const provider = new ethers.BrowserProvider(window.ethereum); -``` - -With web3.js: - -```typescript -const web3 = new Web3(window.ethereum); -``` - -## Wallets and Accounts - -### Generate Private Key - -With ethers.js: - -```typescript -// this would generate a private key similar to: -// '0x286f65c4191759fc5c7e6083b8c275ac2238cc7abb5915bd8c905ae4404215c9' -// (Be sure to store it encrypted in a safe place) -const privateKey = ethers.Wallet.createRandom().privateKey; -``` - -With web3.js: - -```typescript -// this would generate a private key similar to: -// '0x286f65c4191759fc5c7e6083b8c275ac2238cc7abb5915bd8c905ae4404215c9' -// (Be sure to store it encrypted in a safe place) -const privateKey = web3.eth.accounts.create().privateKey; -``` - -### Create a wallet - -In ethers.js: - -```typescript -const wallet = new ethers.Wallet( - // A private key that you might had generated with: - // ethers.Wallet.createRandom().privateKey - privateKey, -); - -// outputs: 0x6f7D735dFB514AA1778E8D97EaCE72BfECE71865 -console.log(wallet.address); -``` - -With web3.js: - -```typescript -const web3 = new Web3(); -const wallet = web3.eth.accounts.wallet.add( - // you can generate a private key using web3.eth.accounts.create().privateKey - privateKey, -); - -// outputs: 0x6f7D735dFB514AA1778E8D97EaCE72BfECE71865 -console.log(wallet[0].address); -``` - -:::info -In web3.js, if you want to use a private key to later sign and send transactions, you first need to add this private key to the accounts with, for example, one of the methods: -`web3.eth.accounts.create()`, or `web3.eth.accounts.wallet.add(privateKey)`. - -And then whenever you provide the public address of that private key, web3.js will use that private key to sign. For example, you would pass the public key at `web3.eth.sendTransaction({from: publicAddress,...})` and web3.`eth.signTransaction({from: publicAddress,...})` then the privateKey of that publicAddress will be lookup and used to sign. - -However, it is not advised to use the privatekey directly. And you are advised to use a secret storage or a vault instead. -::: - -### Get unlocked account - -With ethers.js: - -```typescript -const signer = await provider.getSigner(); -``` - -With web3.js: - -```typescript -const account = (await web3.eth.getAccounts())[0]; -``` - -### Signing a string message - -with ethers.js: - -```typescript -const signer = new ethers.Wallet(privateKey); - -const signature = await signer.signMessage('Some data'); -// Outputs something like: -// 0xb475e02218d7d6a16f3575de789996d0a57f900f240d73ed792672256d63913840c1da0dd3e7fe2e79485b7a1d81e8cc163f405c3df22d496f28f1dd148faebf1b -console.log(signature); -``` - -With web3.js: - -```typescript -// Sign with web3.js, using a private key: -const signature = web3.eth.accounts.sign('Some data', privateKey).signature; - -// Outputs something like: -// 0xb475e02218d7d6a16f3575de789996d0a57f900f240d73ed792672256d63913840c1da0dd3e7fe2e79485b7a1d81e8cc163f405c3df22d496f28f1dd148faebf1b -console.log(signature); - -// Sign using an account managed by the connected provider (for example the RPC client or a browser-injected provider) -const signature = await web3.eth.sign( - web3.utils.utf8ToHex('Some data'), // data to be signed (4.x only supports Hex Strings) - '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4', // the address that its private key would be used to sign -); - -// Outputs something like: -// 0xb475e02218d7d6a16f3575de789996d0a57f900f240d73ed792672256d63913840c1da0dd3e7fe2e79485b7a1d81e8cc163f405c3df22d496f28f1dd148faebf1b -console.log(signature); -``` - -## Signing and Sending Transactions - -### Sending Transactions - -Sending a transaction with ethers.js: - -```typescript -const signer = new ethers.Wallet(privateKey, provider); - -const tx = await signer.sendTransaction({ - to: '0x92d3267215Ec56542b985473E73C8417403B15ac', - value: ethers.parseUnits('0.001', 'ether'), -}); -console.log(tx); -``` - -With web3.js: - -:::info -The method `web3.eth.sendTransaction` will use the account that you pass the public address at `from` to sign the transaction. - -So, the `from` needs to be the public address of a private key that you added previously to the web3.eth.accounts. Or, else, it would pass it to the provider where an unlocked account would be used. - -And for the case when you did not add the private key early, and so the `from` was just passed to the provider. Then if the provider was a browser-injected provider like metamask, for example, it will ask the user to sign. And, if you are using a local dev node as a provider, it should be one of the accounts that were already unlocked at the node. However, note that it is highly risky and not recommended to unlock an account at a production or even a test node. -::: - -```typescript -const web3 = new Web3(url); - -// The method web3.eth.sendTransaction is helpful if you are using a browser-injected provider like metamask. -// Or, if you are using a local dev node like ganache; and you have some accounts already unlocked at the node. -// And this is how you would get the first unlocked account from a local node (not advised for production or even on test node to use unlock accounts on the node). -const account = (await web3.eth.getAccounts())[0]; - -// Alternative to the above, here is how to add wallet to be used as a signer later: -const wallet = web3.eth.accounts.wallet.add(privateKey); -const account = wallet[0].address; - -const tx = await web3.eth.sendTransaction({ - from: account, - to: '0x92d3267215Ec56542b985473E73C8417403B15ac', - value: web3.utils.toWei('0.00000000001', 'ether'), -}); -console.log(tx); -``` - -### Sending a Signed Transactions - -Posting a signed transaction to the node with ethers.js: - -```typescript -// in v5 -provider.sendTransaction(signedTx); - -// in v6 -provider.broadcastTransaction(signedTx); -``` - -With web3.js: - -```typescript -const transaction: Transaction = { - from: senderPublicAddress, - to: receiverPublicAddress, - value: 1, - gas: 21000, - type: 0, -}; - -// you might also use below `web3.eth.personal.signMessage`, depending on your use case. -const signedTransaction = await web3.eth.accounts.signTransaction(transaction, privateKey); - -const tx = await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction); - -console.log(tx); -``` - -## Contracts - -### Contracts Deployment - -To deploy a contract in ethers.js you might have something like: - -```typescript -const signer = provider.getSigner(); -const factory = new ethers.ContractFactory(abi, bytecode, signer); -const contract = await factory.deploy('constructor param'); -console.log('contract address', contract.address); - -// wait for contract creation transaction to be mined -await contract.deployTransaction.wait(); -``` - -In web3.js: - -```typescript -const contractObject = new web3.eth.Contract(abi); -const deployedContract = await contractObject - .deploy({ - data: bytecode, - arguments: ['constructor param'], - }) - .send({ - from: '0x12598d2Fd88B420ED571beFDA8dD112624B5E730', - gas: '1000000', - // other transaction's params - }); - -console.log('contract address', deployedContract.options.address); -``` - -:::tip -πŸ“ To get the smart contract ABI, you are advised to check: [#Step 4: Compile the Solidity code using the Solidity Compiler and get its ABI and Bytecode](/guides/smart_contracts/smart_contracts_guide#step-4-compile-the-solidity-code-using-the-solidity-compiler-and-get-its-abi-and-bytecode) and [Infer Contract Types from JSON Artifact](/guides/smart_contracts/infer_contract_types/) -::: - -### Calling Contracts' Methods - -To interact with contracts in ethers.js: - -```typescript -const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, providerOrSigner); -const result = await contract.someFunction(); -``` - -In web3.js: - -```typescript -const web3 = new Web3(provider); -const contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); - -// If the method was only to read form the Blockchain: -const result = await contract.methods.someFunction().call(); -// Or, if the method would need a transaction to be sent: -const result = await contract.methods.someFunction().send(); -``` - -#### Contracts Overloaded Methods - -In ethers.js: - -```typescript -// ethers -const abi = [ - 'function getMessage(string) public view returns (string)', - 'function getMessage() public view returns (string)', -]; -const contract = new ethers.Contract(address, abi, signer); - -// for ambiguous functions (two functions with the same -// name), the signature must also be specified -message = await contract['getMessage(string)']('nice'); -// and to call the overladed method without a parameter: -message = await contract['getMessage()'](); - -// in v6 -contract.foo(Typed.string('nice')); -``` - -In web3.js: - -```typescript -// in web3.js the overloaded method implementation is automatically picked based on the passed datatype -message = await contract.methods.getMessage('nice').call(); -// To call the overladed method without a parameter: -message = await contract.methods.getMessage().call(); -``` - -### Gas Estimation - -To interact with contracts in ethers.js: - -```typescript -// Estimate the gas -contract.myMethod.estimateGas(123); -``` - -In web3.js: - -```typescript -// Estimate the gas -const gasAmount = await myContract.methods.myMethod(123).estimateGas( - { gas: 5000000, from: transactionSenderAddress }, // optional -); -``` - -### Handling Events - -Handling events with ethers.js: - -```typescript -contract.on('SomeEvent', (arg1, arg2, event) => { - // event handling -}); -``` - -With web3.js: - -```typescript -const event = contract.events.SomeEvent({ - filter: { - filter: { val: 100 }, - }, - fromBlock: 0, -}); - -event.on('data', resolve); -event.on('error', reject); -``` - -## Utility methods - -### Hashing - -Here is how to compute `keccak256` hash of a UTF-8 string with web3 and ethers. - -With ethers.js: - -```typescript -// hash of a string -ethers.utils.id('hello world'); -// hash of binary data -ethers.utils.keccak256('0x4242'); -``` - -With web3.js: - -```typescript -// computes the Keccak-256 hash of the input and returns a hexstring: -// the `utils.sha3` accepts: string and Uint8Array -web3.utils.sha3('hello world'); -// the `utils.keccak256` accepts: string, Uint8Array, Numbers and ReadonlyArray -web3.utils.keccak256('hello world'); -``` - -### Ethers Conversion - -Here is how to convert from and to ether units. - -With ethers.js: - -```typescript -const fromWieToEther = ethers.formatEther('1000000000000000000'); -// outputs: 1.0 -console.log(fromWieToEther); - -const fromEtherToWie = ethers.parseEther('1.0'); -// outputs: 1000000000000000000n -console.log(fromEtherToWie); -``` - -With web3.js: - -```typescript -// the second parameter is 'the unit to convert to' -const fromWieToEther = Web3.utils.fromWei('1000000000000000000', 'ether'); -// outputs: 1 -console.log(fromWieToEther); - -// the second parameter is 'the unit of the number passed' -const fromEtherToWie = Web3.utils.toWei('1.0', 'ether'); -// outputs: 1000000000000000000 -console.log(fromEtherToWie); -``` - -## Conclusion - -This guide should provide a starting point for migrating from ethers.js to web3.js version 4.x. Remember to adapt the example code to your actual use case and verify the function arguments and setup as you migrate your application. And the official documentation of web3.js is your go-to resource for detailed information and updates. diff --git a/docs/docs/guides/18_migration_viem/index.md b/docs/docs/guides/18_migration_viem/index.md new file mode 100644 index 00000000000..b4fee378ebd --- /dev/null +++ b/docs/docs/guides/18_migration_viem/index.md @@ -0,0 +1,263 @@ +--- +sidebar_label: 'πŸ”„ Migration to Viem' +title: 'Migration from Web3.js to Viem' +position: 18 +--- + +# Migration from Web3.js to Viem + +This guide will help you migrate from Web3.js v4 to Viem v2 for interacting with the Ethereum blockchain. The guide provides code examples for both libraries for transition. + +## Installation + +To begin migrating from Web3.js to Viem, first install the Viem package: + +```bash +npm install viem@2 +``` + +## Providers + +When migrating from Web3.js to Viem, the first step is to update how you connect to the Ethereum network. Both libraries use providers, but their initialization differs. + +```javascript +import Web3 from 'web3'; + +const web3 = new Web3(providerURL); +``` + +To migrate this to Viem, you'll need to replace it with using `createPublicClient()`. This function creates a client for interacting with the Ethereum network. + +```javascript +import { createPublicClient, http } from 'viem'; + +const client = createPublicClient({ transport: http(providerURL) }); +``` + +## Browser-injected Provider + +For browser wallet connections like MetaMask, update how you handle the injected provider. + +```javascript +const web3 = new Web3(window.ethereum); +``` + +To migrate this to Viem, you'll need to use `createWalletClient()` with `custom()` instead of creating a new Web3 instance. + +```javascript +import { createWalletClient, custom } from 'viem'; +import { mainnet } from 'viem/chains'; + +const client = createWalletClient({ + chain: mainnet, + transport: custom(window.ethereum), +}); +``` + +## Wallets and Accounts - Generate Private Key + +If your code generates private keys, here’s how to migrate that functionality. In web3.js if you are using: + +```javascript +const privateKey = web3.eth.accounts.create().privateKey; +console.log(privateKey); +``` + +To migrate this to Viem, you'll use the `generatePrivateKey()` function from the 'viem/accounts' module. + +```javascript +import { generatePrivateKey } from 'viem/accounts'; + +const privateKey = generatePrivateKey(); +console.log(privateKey); +``` + +## Wallets and Accounts - Create a Wallet + +When migrating from Web3.js to Viem, you'll need to update how you create and manage wallets. The process of adding accounts to wallets differs between the two libraries. In web3.js : + +```javascript +const web3 = new Web3(); +const wallet = web3.eth.accounts.wallet.add(privateKey); +console.log(wallet[0].address); +``` + +To migrate this to Viem, you'll use privateKeyToAccount() to create an account, and then can pass it to createWalletClient() for using it with client. + +```javascript +import { createWalletClient, http } from 'viem'; +import { privateKeyToAccount } from 'viem/accounts'; +import { mainnet } from 'viem/chains'; + +const account = privateKeyToAccount(privateKey); + +const client = createWalletClient({ + account, + chain: mainnet, + transport: http(), +}); +``` + +## Signing Messages + +Update how you handle message signing, following is web3.js example: + +```javascript +const signature = web3.eth.accounts.sign('Some data', privateKey).signature; +console.log(signature); +``` + +To sign message using Viem, you can use `signMessage()` method. + +```javascript +import { createWalletClient, custom } from 'viem' +import { mainnet } from 'viem/chains' + +const walletClient = createWalletClient({ + chain: mainnet, + transport: custom(window.ethereum!), +}); + +const [account] = await walletClient.getAddresses(); + +const signature = await walletClient.signMessage({ + account, + message: 'Some data', +}); + +``` + +## Transaction + +When migrating transaction sending code, you'll need to update how transactions are signed and sent. + +```javascript +const tx = await web3.eth.sendTransaction({ + from: account, + to: '0x92d3267215Ec56542b985473E73C8417403B15ac', + value: web3.utils.toWei('0.001', 'ether'), +}); +``` + +In Viem there is `sendTransaction()` function avalible with walletClient. + +```javascript +import { createWalletClient, custom, parseEther } from 'viem' +import { mainnet } from 'viem/chains' + +const walletClient = createWalletClient({ + chain: mainnet, + transport: custom(window.ethereum!), +}); + +const [account] = await walletClient.getAddresses(); + +const hash = await walletClient.sendTransaction({ + account, + to: '0x92d3267215Ec56542b985473E73C8417403B15ac', + value: parseEther('0.001') +}); + +``` + +## Contracts + +### Contract Deployment + +When migrating contract deployment code, you'll need to update from Web3.js's deploy and send pattern: + +```javascript +// use existing web3 instance connected with provider +const contract = new web3.eth.Contract(abi); +const deployTx = await contract + .deploy({ + data: bytecode, + arguments: ['constructor param'], + }) + .send({ + from: account, + gas: '1000000', + }); +console.log(deployTx.options.address); +``` + +In Viem there is `deployContract()` function that can be used for contracts deployment. + +```javascript +//import { deployContract } from 'viem' +import { createWalletClient, custom } from 'viem'; +import { mainnet } from 'viem/chains'; + +const walletClient = createWalletClient({ + chain: mainnet, + transport: custom(window.ethereum), +}); + +const hash = await walletClient.deployContract({ + abi, + account, //given account + args: ['constructor param'], + bytecode: bytecode, +}); +``` + +### Contract Method Calls + +When migrating contract method calls, you'll need to update from Web3.js's `contract.methods.someFunction().call()` + +```javascript +const contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); +const result = await contract.methods.someFunction().call(); +console.log(result); +``` + +In Viem `readContract()` function can be used for method calls. + +```javascript +const data = await publicClient.readContract({ + address: '0x92d3267215Ec56542b985473E73C8417403B15ac', + abi: wagmiAbi, + functionName: 'tokenTotalSupply', +}); +``` + +### Contract Events + +When migrating event handling code, you'll need to update from Web3.js's events code : + +```javascript +const event = contract.events.SomeEvent({ fromBlock: 0 }); +event.on('data', resolve); +event.on('error', reject); +``` + +In Viem there is `watchContractEvent()` function. + +```javascript +const unwatch = publicClient.watchContractEvent({ + address: '0x92d3267215Ec56542b985473E73C8417403B15ac', + abi: wagmiAbi, + eventName: 'Transfer', + args: { from: '0x34d3267215Ec56542b985473E73C8417403B1533' }, + onLogs: logs => func(logs), +}); +``` + +## Utility Methods + +### Hashing + +When migrating code that computes Keccak-256 hashes, you'll need to update from Web3.js's utility method: + +``` +// keccak256 method with broader input support in web3.js +const hash = web3.utils.keccak256('hello world'); +``` + +In Viem there is `keccak256()` function for keccak256. + +``` +import { keccak256 , toHex } from 'viem' + +keccak256(toHex('hello world')); +``` diff --git a/docs/docs/guides/18_resources_and_troubleshooting/index.md b/docs/docs/guides/19_resources_and_troubleshooting/index.md similarity index 80% rename from docs/docs/guides/18_resources_and_troubleshooting/index.md rename to docs/docs/guides/19_resources_and_troubleshooting/index.md index 8cf7327d828..119c9420cbc 100644 --- a/docs/docs/guides/18_resources_and_troubleshooting/index.md +++ b/docs/docs/guides/19_resources_and_troubleshooting/index.md @@ -1,5 +1,5 @@ --- -sidebar_position: 18 +sidebar_position: 19 sidebar_label: 'πŸ“š Resources & Troubleshooting' --- @@ -44,6 +44,30 @@ Additional Info: [Facebook/React-native Issue #28492](https://github.com/facebook/react-native/issues/28492#issuecomment-824698934) +### TypeError: Cannot read property 'prototype' of undefined, js engine: hermes + +This error occurs when trying to use Web3.js with React Native. To solve this error, use [the `react-native-quick-crypto` package](https://www.npmjs.com/package/react-native-quick-crypto). + +**Resolution Steps:** + +1. Install `react-native-quick-crypto` as a dependency: + +```bash +yarn add react-native-quick-crypto +``` + +2. Set up `react-native-quick-crypto`: + +```bash +cd ios && pod install +``` + +3. Ensure that Web3.js is imported using the default import, as using a named import does not work: + +```bash +import Web3 from 'web3'; +``` + ## Resources ### [Web3.js v4 course](https://www.youtube.com/watch?v=3ZO_t-Kyr1g&list=PLPn3rQCo3XrP4LbQcOyyHQR8McV7w3HZT) diff --git a/docs/docs/guides/19_feedback/index.md b/docs/docs/guides/20_feedback/index.md similarity index 97% rename from docs/docs/guides/19_feedback/index.md rename to docs/docs/guides/20_feedback/index.md index 05ae7d90fef..657a293b66a 100644 --- a/docs/docs/guides/19_feedback/index.md +++ b/docs/docs/guides/20_feedback/index.md @@ -1,5 +1,5 @@ --- -sidebar_position: 19 +sidebar_position: 20 sidebar_label: 'πŸ—£οΈ Feedback' --- diff --git a/packages/web3-account-abstraction/CHANGELOG.md b/packages/web3-account-abstraction/CHANGELOG.md index 03ad474df40..f560e532293 100644 --- a/packages/web3-account-abstraction/CHANGELOG.md +++ b/packages/web3-account-abstraction/CHANGELOG.md @@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --> -## [0.1.0.rc.0] +## [1.0.0.rc.0] ### Added diff --git a/packages/web3-account-abstraction/README.md b/packages/web3-account-abstraction/README.md index 61d49413a5e..a70a9aa3fc6 100644 --- a/packages/web3-account-abstraction/README.md +++ b/packages/web3-account-abstraction/README.md @@ -53,7 +53,7 @@ yarn add web3-account-abstraction | test:unit | Uses `jest` to run tests under `/test/unit` | [docs]: https://docs.web3js.org/ -[repo]: https://github.com/web3/web3.js/tree/4.x/tools/web3-account-abstraction +[repo]: https://github.com/web3/web3.js/tree/4.x/packages/web3-account-abstraction [npm-image]: https://img.shields.io/github/package-json/v/web3/web3.js/4.x?filename=tools%2Fweb3-account-abstraction%2Fpackage.json [npm-url]: https://npmjs.org/package/web3-account-abstraction [downloads-image]: https://img.shields.io/npm/dm/web3-account-abstraction?label=npm%20downloads diff --git a/packages/web3-account-abstraction/package.json b/packages/web3-account-abstraction/package.json index 530f0a09476..2df534a7ad1 100644 --- a/packages/web3-account-abstraction/package.json +++ b/packages/web3-account-abstraction/package.json @@ -1,6 +1,6 @@ { "name": "web3-account-abstraction", - "version": "0.1.0-rc.0", + "version": "1.0.0-rc.0", "description": "Web3 account abstraction package", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -56,10 +56,10 @@ "typescript": "^5.5.4" }, "dependencies": { - "web3-core": "^4.7.0", - "web3-eth-abi": "^4.4.0", - "web3-types": "^1.9.0", - "web3-utils": "^4.3.2", + "web3-core": "^4.7.1", + "web3-eth-abi": "^4.4.1", + "web3-types": "^1.10.0", + "web3-utils": "^4.3.3", "web3-validator": "^2.0.6" } } diff --git a/packages/web3-core/CHANGELOG.md b/packages/web3-core/CHANGELOG.md index 06c64e305e9..546b8bbd9d5 100644 --- a/packages/web3-core/CHANGELOG.md +++ b/packages/web3-core/CHANGELOG.md @@ -123,7 +123,7 @@ Documentation: ### Added -- Web3Subscription constructor accept a Subscription Manager (as an alternative to accepting Request Manager that is now marked marked as deprecated) (#6210) +- Web3Subscription constructor accept a Subscription Manager (as an alternative to accepting Request Manager that is now marked as deprecated) (#6210) ### Changed @@ -185,7 +185,7 @@ Documentation: - defaultTransactionType is now type 0x2 instead of 0x0 (#6282) - Allows formatter to parse large base fee (#6456) -- The package now uses `EventEmitter` from `web3-utils` that works in node envrioment as well as in the browser. (#6398) +- The package now uses `EventEmitter` from `web3-utils` that works in node environment as well as in the browser. (#6398) ### Fixed @@ -205,7 +205,7 @@ Documentation: ### Changed -- Web3config `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622) +- Web3config `contractDataInputFill` has been defaulted to `data`, instead of `input`. (#6622) ## [4.4.0] @@ -225,7 +225,7 @@ Documentation: ### Added -- Now when existing packages are added in web3, will be avalible for plugins via context. (#7088) +- Now when existing packages are added in web3, will be available for plugins via context. (#7088) ## [4.5.1] @@ -245,4 +245,10 @@ Documentation: - Added new property `ignoreGasPricing` to `Web3ConfigOptions`. If `ignoreGasPricing` is true, gasPrice will not be estimated (#7320) +## [4.7.1] + +### Added + +- Updated Typescript version 4 -> 5 (#7272) + ## [Unreleased] diff --git a/packages/web3-core/package.json b/packages/web3-core/package.json index 856baa3b5b5..7fae25e7df1 100644 --- a/packages/web3-core/package.json +++ b/packages/web3-core/package.json @@ -1,6 +1,6 @@ { "name": "web3-core", - "version": "4.7.0", + "version": "4.7.1", "description": "Web3 core tools for sub-packages. This is an internal package.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -42,13 +42,13 @@ "test:integration": "jest --config=./test/integration/jest.config.js --passWithNoTests" }, "dependencies": { - "web3-errors": "^1.3.0", - "web3-eth-accounts": "^4.2.1", + "web3-errors": "^1.3.1", + "web3-eth-accounts": "^4.3.1", "web3-eth-iban": "^4.0.7", "web3-providers-http": "^4.2.0", "web3-providers-ws": "^4.0.8", - "web3-types": "^1.8.1", - "web3-utils": "^4.3.2", + "web3-types": "^1.10.0", + "web3-utils": "^4.3.3", "web3-validator": "^2.0.6" }, "optionalDependencies": { diff --git a/packages/web3-errors/CHANGELOG.md b/packages/web3-errors/CHANGELOG.md index 2bcd592fb2d..a8b64311f08 100644 --- a/packages/web3-errors/CHANGELOG.md +++ b/packages/web3-errors/CHANGELOG.md @@ -184,4 +184,10 @@ Documentation: - Added optional `statusCode` property of response in ResponseError. +## [1.3.1] + +### Added + +- Updated Typescript version 4 -> 5 (#7272) + ## [Unreleased] diff --git a/packages/web3-errors/package.json b/packages/web3-errors/package.json index 17496f4d2cb..c04551af052 100644 --- a/packages/web3-errors/package.json +++ b/packages/web3-errors/package.json @@ -1,6 +1,6 @@ { "name": "web3-errors", - "version": "1.3.0", + "version": "1.3.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.7.0" + "web3-types": "^1.10.0" }, "devDependencies": { "@types/jest": "^28.1.6", diff --git a/packages/web3-eth-abi/CHANGELOG.md b/packages/web3-eth-abi/CHANGELOG.md index 0b9920eca20..06902627018 100644 --- a/packages/web3-eth-abi/CHANGELOG.md +++ b/packages/web3-eth-abi/CHANGELOG.md @@ -200,4 +200,10 @@ Documentation: - added `decodeFunctionCall` and `decodeFunctionReturn`. (#7345) +## [4.4.1] + +### Added + +- Updated Typescript version 4 -> 5 (#7272) + ## [Unreleased] diff --git a/packages/web3-eth-abi/package.json b/packages/web3-eth-abi/package.json index 8423b96294f..5f38242a8e6 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.4.0", + "version": "4.4.1", "description": "Web3 module encode and decode EVM in/output.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -43,9 +43,9 @@ }, "dependencies": { "abitype": "0.7.1", - "web3-errors": "^1.3.0", - "web3-types": "^1.9.0", - "web3-utils": "^4.3.2", + "web3-errors": "^1.3.1", + "web3-types": "^1.10.0", + "web3-utils": "^4.3.3", "web3-validator": "^2.0.6" }, "devDependencies": { diff --git a/packages/web3-eth-accounts/CHANGELOG.md b/packages/web3-eth-accounts/CHANGELOG.md index e707999a1c2..d308595bde8 100644 --- a/packages/web3-eth-accounts/CHANGELOG.md +++ b/packages/web3-eth-accounts/CHANGELOG.md @@ -189,8 +189,14 @@ Documentation: - `hashMessage` now has a new optional param `skipPrefix` with a default value of `false`. A new function `signRaw` was added to sign a message without prefix. (#7346) -## [Unreleased] +## [4.3.1] ### Removed - Move signature related types to web3-types. Re-export them for backwards compatibility. (#7374) + +### Added + +- Updated Typescript version 4 -> 5 (#7272) + +## [Unreleased] diff --git a/packages/web3-eth-accounts/package.json b/packages/web3-eth-accounts/package.json index 5efdc5d2547..b89699410e7 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.3.0", + "version": "4.3.1", "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.3.0", - "web3-types": "^1.9.0", - "web3-utils": "^4.3.2", + "web3-errors": "^1.3.1", + "web3-types": "^1.10.0", + "web3-utils": "^4.3.3", "web3-validator": "^2.0.6" } } diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index 1e7906decf1..9fa8fe2120b 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -410,4 +410,10 @@ Documentation: - Fix Contract methods input param type any[] (#7340) +## [4.7.2] + +### Added + +- Updated Typescript version 4 -> 5 (#7272) + ## [Unreleased] diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index 3133720681f..fefccf4aae1 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.7.1", + "version": "4.7.2", "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.7.0", - "web3-errors": "^1.3.0", - "web3-eth": "^4.11.0", - "web3-eth-abi": "^4.4.0", - "web3-types": "^1.9.0", - "web3-utils": "^4.3.2", + "web3-core": "^4.7.1", + "web3-errors": "^1.3.1", + "web3-eth": "^4.11.1", + "web3-eth-abi": "^4.4.1", + "web3-types": "^1.10.0", + "web3-utils": "^4.3.3", "web3-validator": "^2.0.6" }, "devDependencies": { @@ -69,7 +69,7 @@ "prettier": "^2.7.1", "ts-jest": "^29.1.1", "typescript": "^5.5.4", - "web3-eth-accounts": "^4.3.0", + "web3-eth-accounts": "^4.3.1", "web3-providers-ws": "^4.0.8" } } diff --git a/packages/web3-eth-contract/src/utils.ts b/packages/web3-eth-contract/src/utils.ts index 5ef2de6d594..b5f5fc75fbf 100644 --- a/packages/web3-eth-contract/src/utils.ts +++ b/packages/web3-eth-contract/src/utils.ts @@ -227,6 +227,29 @@ export const getCreateAccessListParams = ({ return txParams; }; +/** + * Generates the Ethereum address of a contract created via a regular transaction. + * + * This function calculates the contract address based on the sender's address and nonce, + * following Ethereum's address generation rules. + * + * @param from The sender’s Ethereum {@link Address}, from which the contract will be deployed. + * @param nonce The transaction count (or {@link Numbers}) of the sender account at the time of contract creation. + * You can get it here: https://docs.web3js.org/api/web3/class/Web3Eth#getTransactionCount. + * @returns An Ethereum {@link Address} of the contract in checksum address format. + * @throws An {@link InvalidAddressError} if the provided address ('from') is invalid. + * @throws An {@link InvalidNumberError} if the provided nonce value is not in a valid format. + * @example + * ```ts + * const from = "0x1234567890abcdef1234567890abcdef12345678"; + * const nonce = (await web3.eth.getTransactionCount(from)) + 1; // The nonce value for the transaction + * + * const res = createContractAddress(from, nonce); + * + * console.log(res); + * // > "0x604f1ECbA68f4B4Da57D49C2b945A75bAb331208" + * ``` + */ export const createContractAddress = (from: Address, nonce: Numbers): Address => { if (!isAddress(from)) throw new InvalidAddressError(`Invalid address given ${from}`); diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index 36f6fd4b633..75d6b67021e 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -295,4 +295,10 @@ Documentation: - `createNewPendingTransactionFilter` , `createNewFilter` , `createNewBlockFilter` , `uninstallFilter` , `getFilterChanges` and `getFilterLogs` are exported from `Web3Eth` and `filtering_rpc_method_wrappers` (#7353) +## [4.11.1] + +### Added + +- Updated Typescript version 4 -> 5 (#7272) + ## [Unreleased] diff --git a/packages/web3-eth/package.json b/packages/web3-eth/package.json index 536bb91aee4..603fbb53ae0 100644 --- a/packages/web3-eth/package.json +++ b/packages/web3-eth/package.json @@ -1,6 +1,6 @@ { "name": "web3-eth", - "version": "4.11.0", + "version": "4.11.1", "description": "Web3 module to interact with the Ethereum blockchain and smart contracts.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -63,15 +63,15 @@ }, "dependencies": { "setimmediate": "^1.0.5", - "web3-core": "^4.7.0", - "web3-errors": "^1.3.0", - "web3-eth-abi": "^4.4.0", - "web3-eth-accounts": "^4.3.0", + "web3-core": "^4.7.1", + "web3-errors": "^1.3.1", + "web3-eth-abi": "^4.4.1", + "web3-eth-accounts": "^4.3.1", "web3-net": "^4.1.0", "web3-providers-ws": "^4.0.8", "web3-rpc-methods": "^1.3.0", - "web3-types": "^1.9.0", - "web3-utils": "^4.3.2", + "web3-types": "^1.10.0", + "web3-utils": "^4.3.3", "web3-validator": "^2.0.6" } } diff --git a/packages/web3-rpc-providers/CHANGELOG.md b/packages/web3-rpc-providers/CHANGELOG.md index 4bc16682b31..185818784ce 100644 --- a/packages/web3-rpc-providers/CHANGELOG.md +++ b/packages/web3-rpc-providers/CHANGELOG.md @@ -64,4 +64,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - PublicNodeProvider was added (#7322) +## [1.0.0-rc.4] + +### Added + +- Updated Typescript version 4 -> 5 (#7272) + ## [Unreleased] diff --git a/packages/web3-rpc-providers/package.json b/packages/web3-rpc-providers/package.json index 028c7f49050..affda08aba1 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.3", + "version": "1.0.0-rc.4", "description": "Web3 Providers package", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -57,11 +57,11 @@ "typescript": "^5.5.4" }, "dependencies": { - "web3-errors": "^1.3.0", + "web3-errors": "^1.3.1", "web3-providers-http": "^4.2.0", "web3-providers-ws": "^4.0.8", - "web3-types": "^1.9.0", - "web3-utils": "^4.3.2", + "web3-types": "^1.10.0", + "web3-utils": "^4.3.3", "web3-validator": "^2.0.6" } } diff --git a/packages/web3-types/CHANGELOG.md b/packages/web3-types/CHANGELOG.md index c78df9f3265..6fb34da9926 100644 --- a/packages/web3-types/CHANGELOG.md +++ b/packages/web3-types/CHANGELOG.md @@ -220,8 +220,11 @@ Documentation: - `FilterParams` type added (#7353) -## [Unreleased] +## [1.10.0] #### Added - Add signature related types. (#7374) +- Updated Typescript version 4 -> 5 (#7272) + +## [Unreleased] diff --git a/packages/web3-types/package.json b/packages/web3-types/package.json index 5fa5b7e1da7..375fe3d4fde 100644 --- a/packages/web3-types/package.json +++ b/packages/web3-types/package.json @@ -1,6 +1,6 @@ { "name": "web3-types", - "version": "1.9.0", + "version": "1.10.0", "description": "Provide the common data structures and interfaces for web3 modules.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index b698fcf51ba..76534484624 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -240,8 +240,14 @@ Documentation: - fix `padRight` validation failure on large `uint` (#7265) -## [Unreleased] +## [4.3.3] ### Fixed - Make `fromWei` return "0" when input is `0` (#7387) + +### Added + +- Updated Typescript version 4 -> 5 (#7272) + +## [Unreleased] diff --git a/packages/web3-utils/README.md b/packages/web3-utils/README.md index 78cce56e322..45d0fa685be 100644 --- a/packages/web3-utils/README.md +++ b/packages/web3-utils/README.md @@ -11,7 +11,7 @@ This is a sub-package of [web3.js][repo]. -`web3-utils` This contains useful utility functions for Dapp developers. +`web3-utils` contains useful utility functions for Dapp developers. ## Installation diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index c49a2929bf6..9bc256403ba 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.2", + "version": "4.3.3", "description": "Collection of utility functions used in web3.js.", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -65,8 +65,8 @@ "dependencies": { "ethereum-cryptography": "^2.0.0", "eventemitter3": "^5.0.1", - "web3-errors": "^1.3.0", - "web3-types": "^1.8.1", + "web3-errors": "^1.3.1", + "web3-types": "^1.10.0", "web3-validator": "^2.0.6" } } diff --git a/packages/web3-validator/CHANGELOG.md b/packages/web3-validator/CHANGELOG.md index 8410b156c08..2a1af7cfee7 100644 --- a/packages/web3-validator/CHANGELOG.md +++ b/packages/web3-validator/CHANGELOG.md @@ -173,6 +173,10 @@ Documentation: ### Fixed - The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981) -- `browser` entry point that was pointing to an non-existing bundle file was removed from `package.json` (#7015) +- `browser` entry point that was pointing to a non-existing bundle file was removed from `package.json` (#7015) ## [Unreleased] + +### Added + +- Add web3-validator dist path for react-native builds (#7416) diff --git a/packages/web3-validator/package.json b/packages/web3-validator/package.json index bff4e5a7c59..eacbfd5ddc2 100644 --- a/packages/web3-validator/package.json +++ b/packages/web3-validator/package.json @@ -11,6 +11,7 @@ "require": "./lib/commonjs/index.js" } }, + "./dist/web3-validator.min.js": "./dist/web3-validator.min.js", "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", diff --git a/packages/web3/CHANGELOG.md b/packages/web3/CHANGELOG.md index b1f440e0074..3bceff19ce3 100644 --- a/packages/web3/CHANGELOG.md +++ b/packages/web3/CHANGELOG.md @@ -316,7 +316,7 @@ Documentation: #### web3-validator - The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981) -- `browser` entry point that was pointing to an non-existing bundle file was removed from `package.json` (#7015) +- `browser` entry point that was pointing to a non-existing bundle file was removed from `package.json` (#7015) #### web3-core @@ -560,10 +560,69 @@ Documentation: - Fix Contract methods input param type any[] (#7340) -## [Unreleased] +## [4.16.0] ### Fixed #### web3 - Export Web3Account, Wallet and signature related types. (#7374) + +#### web3-utils + +- Make `fromWei` return "0" when input is `0` (#7387) + +### Removed + +#### web3-eth-accounts + +- Move signature related types to web3-types. Re-export them for backwards compatibility. (#7374) + +### Added + +#### web3-types + +- Add signature related types. (#7374) +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-eth-accounts + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3 + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-core + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-account-abstraction + +- RC release + +#### web3-errors + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-eth + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-eth-contract + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-rpc-providers + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-utils + +- Updated Typescript version 4 -> 5 (#7272) + +#### web3-eth-abi + +- Updated Typescript version 4 -> 5 (#7272) + +## [Unreleased] diff --git a/packages/web3/package.json b/packages/web3/package.json index 8669034a092..fbb92b9697a 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -1,6 +1,6 @@ { "name": "web3", - "version": "4.15.0", + "version": "4.16.0", "description": "Ethereum JavaScript API", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", @@ -86,12 +86,12 @@ "web3-providers-ipc": "^4.0.7" }, "dependencies": { - "web3-core": "^4.7.0", - "web3-errors": "^1.3.0", - "web3-eth": "^4.11.0", - "web3-eth-abi": "^4.4.0", - "web3-eth-accounts": "^4.3.0", - "web3-eth-contract": "^4.7.1", + "web3-core": "^4.7.1", + "web3-errors": "^1.3.1", + "web3-eth": "^4.11.1", + "web3-eth-abi": "^4.4.1", + "web3-eth-accounts": "^4.3.1", + "web3-eth-contract": "^4.7.2", "web3-eth-ens": "^4.4.0", "web3-eth-iban": "^4.0.7", "web3-eth-personal": "^4.1.0", @@ -99,9 +99,9 @@ "web3-providers-http": "^4.2.0", "web3-providers-ws": "^4.0.8", "web3-rpc-methods": "^1.3.0", - "web3-rpc-providers": "^1.0.0-rc.3", - "web3-types": "^1.9.0", - "web3-utils": "^4.3.2", + "web3-rpc-providers": "^1.0.0-rc.4", + "web3-types": "^1.10.0", + "web3-utils": "^4.3.3", "web3-validator": "^2.0.6" } } diff --git a/packages/web3/src/version.ts b/packages/web3/src/version.ts index ca906081781..64298450599 100644 --- a/packages/web3/src/version.ts +++ b/packages/web3/src/version.ts @@ -1 +1 @@ -/* eslint-disable header/header */ export const Web3PkgInfo = { version: '4.15.0' }; +/* eslint-disable header/header */ export const Web3PkgInfo = { version: '4.16.0' };