Skip to content

Commit

Permalink
Merge branch '4.x' into fix-7219-add-changelog-check
Browse files Browse the repository at this point in the history
  • Loading branch information
whitemoshui authored Dec 12, 2024
2 parents abb48c1 + ae99434 commit ea7013b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2864,3 +2864,9 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
- Updated Typescript version 4 -> 5 (#7272)

## [Unreleased]

### Added

#### web3-validator

- Add web3-validator dist path for react-native builds (#7416)
24 changes: 24 additions & 0 deletions docs/docs/guides/18_resources_and_troubleshooting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions packages/web3-eth-contract/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
4 changes: 4 additions & 0 deletions packages/web3-validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,7 @@ Documentation:
- `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)
1 change: 1 addition & 0 deletions packages/web3-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ea7013b

Please sign in to comment.