Skip to content

Commit

Permalink
add section at migration guide for toHex (#6683)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba authored Jan 5, 2024
1 parent 0c67cc6 commit df594c9
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ web3.utils.toWei('0.1');
web3.utils.toWei('0.1', 'ether');
```

## Conversion to Hex

The `toHex` behave exactly the same in both v1.x and 4.x, except for a string that contains only numbers. In 1.x if a number was provided inside a string like `123` it used to be treated as a number. While in 4.x it will be treated as a string, except if it was prefixed with `0x`. For more clarity, check below:

```ts
// 1.x
new Web3().utils.toHex(0x1) // returns 0x1
new Web3().utils.toHex('0x1') // returns 0x1
new Web3().utils.toHex(1) // returns 0x1
new Web3().utils.toHex('1') // returns 0x1

// 4.x
new Web3().utils.toHex(0x1) // returns 0x1
new Web3().utils.toHex('0x1') // returns 0x1
new Web3().utils.toHex(1) // returns 0x1
new Web3().utils.toHex('1') // returns 0x31
```

## Validation functions

Validation functions has been moved to the new package `web3-validator`. Actually, you can still import them from `web3-util`. But they are marked as "deprecated" and you are encouraged to import them from `web3-validator`.
Expand Down

1 comment on commit df594c9

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: df594c9 Previous: 6c075db Ratio
processingTx 9116 ops/sec (±4.09%) 9301 ops/sec (±4.81%) 1.02
processingContractDeploy 38059 ops/sec (±7.71%) 39129 ops/sec (±7.62%) 1.03
processingContractMethodSend 19926 ops/sec (±7.44%) 19443 ops/sec (±5.19%) 0.98
processingContractMethodCall 39918 ops/sec (±5.77%) 38971 ops/sec (±6.34%) 0.98
abiEncode 45886 ops/sec (±6.62%) 44252 ops/sec (±6.92%) 0.96
abiDecode 30584 ops/sec (±8.31%) 30419 ops/sec (±8.89%) 0.99
sign 1676 ops/sec (±3.19%) 1656 ops/sec (±4.08%) 0.99
verify 385 ops/sec (±0.69%) 373 ops/sec (±0.78%) 0.97

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

Please sign in to comment.