From 5ec280d6cdc69f653731d5fb65fc8468938a8853 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 14 Jun 2022 17:14:12 -1000 Subject: [PATCH 01/18] Init web3_eth_migration_guide --- docs/docs/guides/web3_eth_migration_guide.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 docs/docs/guides/web3_eth_migration_guide.md diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md new file mode 100644 index 00000000000..f34b4ad0e77 --- /dev/null +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -0,0 +1,14 @@ +# Web3Eth Migration Guide + +## Breaking Changes + +- `givenProvider` default value is `undefined` instead of `null` +- `currentProvider` will never return `null`, provider required upon instantiation as opposed to being optional in 1.x +- `extend` functionality not implemented +- `web3.eth.defaultAccount` default value is `undefined` instead of `null` + - 1.x has `undefined` documented as default, but in implementation it's `null` +- `web3.eth.defaultHardfork` default is `london` instead of `undefined` + - 1.x has `london` documented as default, but in implementation it's `undefined` +- `web3.eth.defaultChain` default is `mainnet` instead of `undefined` + - 1.x has `mainnet` documented as default, but in implementation it's `undefined` +- `web3.eth.createAccessList` not implemented From c2f7d68650ab2e2468fda6d9f405439790778f92 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Tue, 14 Jun 2022 20:38:12 -1000 Subject: [PATCH 02/18] WIP migration guide --- docs/docs/guides/web3_eth_migration_guide.md | 500 ++++++++++++++++++- 1 file changed, 498 insertions(+), 2 deletions(-) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index f34b4ad0e77..4f32ff8fa4a 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -2,13 +2,509 @@ ## Breaking Changes +### Not Implemented or Exported + +- `extend` functionality not implemented +- `web3.eth.createAccessList` not implemented +- `web3.eth.personal` namespace is not exported +- `web3.eth.net` namespace is not exported + +### Defaults and Configs + - `givenProvider` default value is `undefined` instead of `null` - `currentProvider` will never return `null`, provider required upon instantiation as opposed to being optional in 1.x -- `extend` functionality not implemented - `web3.eth.defaultAccount` default value is `undefined` instead of `null` - 1.x has `undefined` documented as default, but in implementation it's `null` - `web3.eth.defaultHardfork` default is `london` instead of `undefined` - 1.x has `london` documented as default, but in implementation it's `undefined` - `web3.eth.defaultChain` default is `mainnet` instead of `undefined` - 1.x has `mainnet` documented as default, but in implementation it's `undefined` -- `web3.eth.createAccessList` not implemented + +### Web3Eth Methods + +### `web3.eth.getHashrate` + +renamed to `getHashRate` + +### `web3.eth.getGasPrice` + +returns a hex string instead of a number string + +```typescript +// in 1.x +await web3.eth.getGasPrice(); // '2000000000' + +// in 4.x +await web3.eth.getGasPrice(); // '0x77359400' +``` + +### `web3.eth.getFeeHistory` + +returns hex strings for `gasUsedRation` array items instead of a numbers + +```typescript +// in 1.x +await web3.eth.getFeeHistory('0x1', 'latest', []); +// { +// oldestBlock: '0x0', +// baseFeePerGas: [ '0x3b9aca00', '0x342770c0' ], +// gasUsedRatio: [ 0 ] +// } + +// in 4.x +await web3.eth.getFeeHistory('0x1', 'latest', []); +// { +// oldestBlock: '0x0', +// baseFeePerGas: [ '0x3b9aca00', '0x342770c0' ], +// gasUsedRatio: [ '0x0' ] +// } +``` + +### `web3.eth.getAccounts` + +addresses are not returned as checksum + +```typescript +// in 1.x +await web3.eth.getAccounts(); +// ['0xAB089B30f46883C3598B720d85837080b9929D0B'] + +// in 4.x +await web3.eth.getAccounts(); +// ['0xab089b30f46883c3598b720d85837080b9929d0b'] +``` + +### `web3.eth.getBlockNumber` + +returns a hex string instead of a number + +```typescript +// in 1.x +await web3.eth.getBlockNumber(); // 0 + +// in 4.x +await web3.eth.getBlockNumber(); // '0x0' +``` + +### `web3.eth.getBalance` + +returns a hex string instead of a number string + +```typescript +// in 1.x +await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // '115792089237316195423570985008687907853269984665640564039457584007913129639927' + +// in 4.x +await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7' +``` + +### `web3.eth.getBlock` + +- Returns a hex string instead of a number for the following properties: + - `baseFeePerGas` + - `gasLimit` + - `gasUsed` + - `number` + - `size` + - `timestamp` +- Returns a hex string instead of a number string for the following properties: + - `difficulty` + - `totalDifficulty` + +```typescript +// in 1.x +await web3.eth.getBlock('latest'); +// { +// baseFeePerGas: 1000000000, +// difficulty: '1', +// extraData: '0x0000000000000000000000000000000000000000000000000000000000000000ab089b30f46883c3598b720d85837080b9929d0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// gasLimit: 11500000, +// gasUsed: 0, +// hash: '0x898f2ec817477ef26f0f84e4070840ca9f020fdc2fd4c0375df051da96b93045', +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// miner: '0x0000000000000000000000000000000000000000', +// mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', +// nonce: '0x0000000000000000', +// number: 0, +// parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', +// receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', +// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', +// size: 627, +// stateRoot: '0xcdbd36dbc4916d258879c5d4fccfc54c6dc0cbd39a6dba5be19e09f4b8e6587d', +// timestamp: 0, +// totalDifficulty: '1', +// transactions: [], +// transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', +// uncles: [] +// } + +// in 4.x +await web3.eth.getBlock('latest'); +// { +// baseFeePerGas: '0x3b9aca00', +// difficulty: '0x1', +// extraData: '0x0000000000000000000000000000000000000000000000000000000000000000ab089b30f46883c3598b720d85837080b9929d0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// gasLimit: '0xaf79e0', +// gasUsed: '0x0', +// hash: '0x898f2ec817477ef26f0f84e4070840ca9f020fdc2fd4c0375df051da96b93045', +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// miner: '0x0000000000000000000000000000000000000000', +// mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', +// nonce: '0x0', +// number: '0x0', +// parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', +// receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', +// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', +// size: '0x273', +// stateRoot: '0xcdbd36dbc4916d258879c5d4fccfc54c6dc0cbd39a6dba5be19e09f4b8e6587d', +// timestamp: '0x0', +// totalDifficulty: '0x1', +// transactions: [], +// transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', +// uncles: [] +// } +``` + +### `web3.eth.getBlockTransactionCount` + +returns a hex string instead of a number + +```typescript +// in 1.x +await web3.eth.getBlockTransactionCount('latest'); // 0 + +// in 4.x +await web3.eth.getBlockTransactionCount('latest'); // '0x0' +``` + +### `web3.eth.getBlockUncleCount` + +returns a hex string instead of a number + +```typescript +// in 1.x +await web3.eth.getBlockUncleCount('latest'); // 0 + +// in 4.x +await web3.eth.getBlockUncleCount('latest'); // '0x0' +``` + +### `web3.eth.getUncle` + +- Returns a hex string instead of a number for the following properties: + - `baseFeePerGas` + - `gasLimit` + - `gasUsed` + - `number` + - `size` + - `timestamp` +- Returns a hex string instead of a number string for the following properties: + - `difficulty` + +```typescript +// in 1.x +await web3.eth.getUncle(14965991, 0); +// { +// baseFeePerGas: 35571562105, +// difficulty: '13923582981852799', +// extraData: '0x617369612d65617374322d3132', +// gasLimit: 30087829, +// gasUsed: 11487217, +// hash: '0xf049e44dba7ae7c45239de3e2264ead7abd86fec3399ae2234edf778e936885c', +// logsBloom: '0x206cab47e94018b154281022c05863330003318c70a0ca4460244b4134a88517302d93c854b8068110a11b1342212335ba2020000d12fc330a44489e013e20149006f2034180105e7a820219b52861a241a210ca8d50385d3c481c21a8406c509a584cb15a226e0620111a884c262b9236010cf444700c030e2480f7200a6484b22b15a012c29903b40c0cc4830304c665003cc1b1b240b8752087d8ea1261e2ef8e293711c26d3b2b87c0988dd928d2d1a427340a90900641270ea6008a4d10032424ef0c0209789b424b4c304f5a0700640a40dfae02506303396e85182021203170182904980140409004cde41f818c21c80009480172c26f39944202fc83', +// miner: '0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8', +// mixHash: '0xfde990a5350c56b44f0538a0b28d6d26d87f59934477ef73908b9d96c91d6e59', +// nonce: '0xea5a783eb0e0e46b', +// number: 14965990, +// parentHash: '0xef7f2e8cb41f37c021b236bc3ea9d2c4e6b0fceefdb3c2c646384b7b2fe116a5', +// receiptsRoot: '0x327f816a10ba5bcc702055d419baa731346131cc2dda49e64b7ba9e5a7fd49bb', +// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', +// size: 541, +// stateRoot: '0x4276888e92368eac990a4bbcda938c9c29bd94f85b134b218990d1b137dc234d', +// timestamp: 1655273068, +// transactionsRoot: '0x1717925d728173ce122b91199383468dbce68bda5e308d2a16f00725bab7b140', +// uncles: [] +// } + +// in 4.x +await web3.eth.getUncle(14965991, 0); +// { +// baseFeePerGas: '0x8483af679', +// difficulty: '0x31776cc9a24e7f', +// extraData: '0x617369612d65617374322d3132', +// gasLimit: '0x1cb1a95', +// gasUsed: '0xaf47f1', +// hash: '0xf049e44dba7ae7c45239de3e2264ead7abd86fec3399ae2234edf778e936885c', +// logsBloom: '0x206cab47e94018b154281022c05863330003318c70a0ca4460244b4134a88517302d93c854b8068110a11b1342212335ba2020000d12fc330a44489e013e20149006f2034180105e7a820219b52861a241a210ca8d50385d3c481c21a8406c509a584cb15a226e0620111a884c262b9236010cf444700c030e2480f7200a6484b22b15a012c29903b40c0cc4830304c665003cc1b1b240b8752087d8ea1261e2ef8e293711c26d3b2b87c0988dd928d2d1a427340a90900641270ea6008a4d10032424ef0c0209789b424b4c304f5a0700640a40dfae02506303396e85182021203170182904980140409004cde41f818c21c80009480172c26f39944202fc83', +// miner: '0xea674fdde714fd979de3edf0f56aa9716b898ec8', +// mixHash: '0xfde990a5350c56b44f0538a0b28d6d26d87f59934477ef73908b9d96c91d6e59', +// nonce: '0xea5a783eb0e0e46b', +// number: '0xe45ce6', +// parentHash: '0xef7f2e8cb41f37c021b236bc3ea9d2c4e6b0fceefdb3c2c646384b7b2fe116a5', +// receiptsRoot: '0x327f816a10ba5bcc702055d419baa731346131cc2dda49e64b7ba9e5a7fd49bb', +// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', +// size: '0x21d', +// stateRoot: '0x4276888e92368eac990a4bbcda938c9c29bd94f85b134b218990d1b137dc234d', +// timestamp: '0x62a9766c', +// transactionsRoot: '0x1717925d728173ce122b91199383468dbce68bda5e308d2a16f00725bab7b140', +// uncles: [] +// } +``` + +### `web3.eth.getTransaction` + +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `gas` + - `nonce` + - `transactionIndex` + - `type` +- Returns a hex string instead of a number string for the following properties: + - `gasPrice` + - `maxFeePerGas` + - `maxPriorityFeePerGas` + - `value` + +```typescript +// in 1.x +await web3.eth.getTransaction('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); +// { +// accessList: [], +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: 14966017, +// chainId: '0x1', +// from: '0x3b7414bE92e87837D6f95D01B8E3c93aC9D20804', +// gas: 21000, +// gasPrice: '31200410061', +// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// input: '0x', +// maxFeePerGas: '56156626189', +// maxPriorityFeePerGas: '1500000000', +// nonce: 272, +// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', +// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', +// to: '0x8b664E252B7c5C87c17e73C69F16E56454C9661F', +// transactionIndex: 80, +// type: 2, +// v: '0x1', +// value: '13066966539051000' +// } + +// in 4.x +await web3.eth.getTransaction('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); +// { +// accessList: [], +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: '0xe45d01', +// chainId: '0x1', +// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', +// gas: '0x5208', +// gasPrice: '0x743b079cd', +// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// input: '0x', +// maxFeePerGas: '0xd13321d0d', +// maxPriorityFeePerGas: '0x59682f00', +// nonce: '0x110', +// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', +// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', +// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', +// transactionIndex: '0x50', +// type: '0x2', +// v: '0x1', +// value: '0x2e6c563ada1ff8' +// } +``` + +### `web3.eth.getPendingTransactions` + +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `gas` + - `nonce` + - `transactionIndex` + - `type` +- Returns a hex string instead of a number string for the following properties: + - `gasPrice` + - `maxFeePerGas` + - `maxPriorityFeePerGas` + - `value` + +```typescript +// in 1.x +await web3.eth.getPendingTransactions(); +// [ +// { +// accessList: [], +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: 14966017, +// chainId: '0x1', +// from: '0x3b7414bE92e87837D6f95D01B8E3c93aC9D20804', +// gas: 21000, +// gasPrice: '31200410061', +// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// input: '0x', +// maxFeePerGas: '56156626189', +// maxPriorityFeePerGas: '1500000000', +// nonce: 272, +// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', +// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', +// to: '0x8b664E252B7c5C87c17e73C69F16E56454C9661F', +// transactionIndex: 80, +// type: 2, +// v: '0x1', +// value: '13066966539051000' +// }, +// ...] + +// in 4.x +await web3.eth.getPendingTransactions(); +// [ +// { +// accessList: [], +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: '0xe45d01', +// chainId: '0x1', +// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', +// gas: '0x5208', +// gasPrice: '0x743b079cd', +// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// input: '0x', +// maxFeePerGas: '0xd13321d0d', +// maxPriorityFeePerGas: '0x59682f00', +// nonce: '0x110', +// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', +// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', +// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', +// transactionIndex: '0x50', +// type: '0x2', +// v: '0x1', +// value: '0x2e6c563ada1ff8' +// }, +// ...] +``` + +### `web3.eth.getTransactionFromBlock` + +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `gas` + - `nonce` + - `transactionIndex` + - `type` +- Returns a hex string instead of a number string for the following properties: + - `gasPrice` + - `maxFeePerGas` + - `maxPriorityFeePerGas` + - `value` + +```typescript +// in 1.x +await web3.eth.getTransactionFromBlock('latest', 1); +// { +// accessList: [], +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: 14966017, +// chainId: '0x1', +// from: '0x3b7414bE92e87837D6f95D01B8E3c93aC9D20804', +// gas: 21000, +// gasPrice: '31200410061', +// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// input: '0x', +// maxFeePerGas: '56156626189', +// maxPriorityFeePerGas: '1500000000', +// nonce: 272, +// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', +// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', +// to: '0x8b664E252B7c5C87c17e73C69F16E56454C9661F', +// transactionIndex: 80, +// type: 2, +// v: '0x1', +// value: '13066966539051000' +// } + +// in 4.x +await web3.eth.getTransactionFromBlock('latest', 1); +// { +// accessList: [], +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: '0xe45d01', +// chainId: '0x1', +// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', +// gas: '0x5208', +// gasPrice: '0x743b079cd', +// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// input: '0x', +// maxFeePerGas: '0xd13321d0d', +// maxPriorityFeePerGas: '0x59682f00', +// nonce: '0x110', +// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', +// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', +// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', +// transactionIndex: '0x50', +// type: '0x2', +// v: '0x1', +// value: '0x2e6c563ada1ff8' +// } +``` + +### `web3.eth.getTransactionReceipt` + +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `cumulativeGasUsed` + - `effectiveGasPrice` + - `gasUsed` + - `transactionIndex` +- Returns a hex string instead of a boolean for the following properties: + - `status` + +```typescript +// in 1.x +await web3.eth.getTransactionReceipt('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); +// { +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: 14966017, +// contractAddress: null, +// cumulativeGasUsed: 6992382, +// effectiveGasPrice: 31200410061, +// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', +// gasUsed: 21000, +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: true, +// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', +// transactionHash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// transactionIndex: 80, +// type: '0x2' +// } + +// in 4.x +await web3.eth.getTransactionReceipt('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); +// { +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: '0xe45d01', +// cumulativeGasUsed: '0x6ab1fe', +// effectiveGasPrice: '0x743b079cd', +// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', +// gasUsed: '0x5208', +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: '0x1', +// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', +// transactionHash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// transactionIndex: '0x50', +// type: '0x2' +// } +``` + +### `web3.eth.getTransactionCount` + +returns a hex string instead of a number + +```typescript +// in 1.x +await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); // 0 + +// in 4.x +await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); // '0x0' +``` From 072d01350399534362bc732d1341e3c929351780 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Wed, 15 Jun 2022 22:32:08 -1000 Subject: [PATCH 03/18] WIP migration guide --- docs/docs/guides/web3_eth_migration_guide.md | 214 ++++++++++++++++++- 1 file changed, 210 insertions(+), 4 deletions(-) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index 4f32ff8fa4a..0bcf6e847f3 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -4,10 +4,10 @@ ### Not Implemented or Exported -- `extend` functionality not implemented -- `web3.eth.createAccessList` not implemented -- `web3.eth.personal` namespace is not exported -- `web3.eth.net` namespace is not exported +- [extend](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#extend) functionality not implemented +- [web3.eth.createAccessList](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#createaccesslist) not implemented +- [web3.eth.personal](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#personal) namespace is not exported +- [web3.eth.net](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#net) namespace is not exported ### Defaults and Configs @@ -508,3 +508,209 @@ await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe') // in 4.x await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); // '0x0' ``` + +### `web3.eth.sendTransaction` + +- `userTransactionObject.chain` no longer defaults to `mainnet`, will be `undefined` if not provided +- `userTransactionObject.hardfork` no longer defaults to `london`, will be `undefined` if not provided + +#### PromiEvents + +##### `sending` + +- In `1.x`, this event listenter would receive a `payload` object as an arguement, in `4.x` just the sent transaction object is recieved + +```typescript +// in 1.x +web3.eth.sendTransaction({ ... }).on('sending', (payload) => { ... }); +// payload would be: +// { +// method: 'eth_sendTransaction', +// params: [ +// { +// from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// to: '0x0000000000000000000000000000000000000000', +// value: '0x1', +// maxPriorityFeePerGas: '0x9502F900', +// maxFeePerGas: '0xc3e17d20' +// } +// ], +// callback: undefined +// } + +// in 4.x +web3.eth.sendTransaction({ ... }).on('sending', (sendTransactionObject) => { ... }); +// sendTransactionObject would be: +// { +// from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// to: '0x0000000000000000000000000000000000000000', +// value: '0x1', +// gasPrice: '0x77359400', +// maxPriorityFeePerGas: undefined, +// maxFeePerGas: undefined +// } +``` + +###### `sent` + +- In `1.x`, this event listenter would receive a `payload` object as an arguement, in `4.x` just the sent transaction object is recieved + +```typescript +// in 1.x +web3.eth.sendTransaction({ ... }).on('sent', (payload) => { ... }); +// payload would be: +// { +// method: 'eth_sendTransaction', +// params: [ +// { +// from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// to: '0x0000000000000000000000000000000000000000', +// value: '0x1' +// } +// ], +// callback: undefined +// } + +// in 4.x +web3.eth.sendTransaction({ ... }).on('sent', (sentTransactionObject) => { ... }); +// sentTransactionObject would be: +// { +// from: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4', +// to: '0x0000000000000000000000000000000000000000', +// value: '0x1', +// gasPrice: '0x77359400', +// maxPriorityFeePerGas: undefined, +// maxFeePerGas: undefined +// } +``` + +##### `receipt` + +- The `receipt` object the event listener receives: + - Returns a hex string instead of a number for the following properties: + - `transactionIndex` + - `blockNumber` + - `cumulativeGasUsed` + - `gasUsed` + - `effectiveGasPrice` + - Returns a hex string instead of a boolean for the following properties: + - `status` + +```typescript +// in 1.x +web3.eth.sendTransaction({ ... }).on('receipt', (receipt) => { ... }); +// receipt would be: +// { +// transactionHash: '0x4f0f428ae3c2f0ec5e054491ecf01a0c38b92ef128350d4831c07ef52f5d4a15', +// transactionIndex: 0, +// blockNumber: 14, +// blockHash: '0x5bb7c47a0fcb8d53fc2d1524873631340c1855c7b98d657de614d4d0554596f8', +// from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// to: '0x0000000000000000000000000000000000000000', +// cumulativeGasUsed: 21000, +// gasUsed: 21000, +// contractAddress: null, +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: true, +// effectiveGasPrice: 2654611504, +// type: '0x2' +// } + +// in 4.x +web3.eth.sendTransaction({ ... }).on('receipt', (receipt) => { ... }); +// receipt would be: +// { +// transactionHash: '0xef37e818889e7b40df24f8546ae15b16cda7e8fdc99ad76356611401cb4c4f93', +// transactionIndex: '0x0', +// blockNumber: '0xf', +// blockHash: '0x8a700d6665a5b91789f7525490c453d55208f7560662aa3ff2eaab8d297bfd07', +// from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// to: '0x0000000000000000000000000000000000000000', +// cumulativeGasUsed: '0x5208', +// gasUsed: '0x5208', +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: '0x1', +// effectiveGasPrice: '0x77359400', +// type: '0x0' +// } +``` + +##### `confirmation` + +- In `1.x`, this event listener would receive `confirmationNumber` and `receipt` as arguments, in `4.x` an object containing the properties: `confirmationNumber`, `receipt`, and `latestBlockHash` will be received +- `confirmationNumber` is returned as a hex string instead of a number +- For the returned `receipt` object: + - Returns a hex string instead of a number for the following properties: + - `transactionIndex` + - `blockNumber` + - `cumulativeGasUsed` + - `gasUsed` + - `effectiveGasPrice` + - Returns a hex string instead of a boolean for the following properties: + - `status` + +```typescript +// in 1.x +web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationNumber, receipt) => { ... }); +// confirmationNumber would be: 1 +// receipt would be: +// { +// transactionHash: '0x1e657e53a0e5a75fe36af8a05c89b8a8ea155c951ce43a7c42a77a48c4c89e2f', +// transactionIndex: 0, +// blockNumber: 2, +// blockHash: '0x940bfb359be8064d7c65408efaba3068bdd6995b810aae5fb355bd3d95d3079b', +// from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// to: '0x0000000000000000000000000000000000000000', +// cumulativeGasUsed: 21000, +// gasUsed: 21000, +// contractAddress: null, +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: true, +// effectiveGasPrice: 3265778125, +// type: '0x2' +// } + +// in 4.x +web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationObject) => { ... }); +// confirmationObject would have the following structure: +// { +// confirmationNumber: '0x2', +// receipt: { +// transactionHash: '0xd93fe25c2066cd8f15565bcff693507a3c70f5fb9387db57f939ae91f4080c6c', +// transactionIndex: '0x0', +// blockNumber: '0x5', +// blockHash: '0xe1775977a8041cb2709136804e4be609135f8367b49d38960f92a95b4c02189a', +// from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// to: '0x0000000000000000000000000000000000000000', +// cumulativeGasUsed: '0x5208', +// gasUsed: '0x5208', +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: '0x1', +// effectiveGasPrice: '0x77359400', +// type: '0x0' +// }, +// latestBlockHash: '0xb2ef3763190da82d8efa938f73efa5bb21e3d95c2ce25dd38ca21eea1a942260' +// } +``` + +- In `1.x`, an event was emitted for each confirmation starting from `0` (the first block the transaction was included in), in `4.x` confirmations start from `1` and the first event to be emitted will have a `confirmationNumber` of `2` + +```typescript +// in 1.x +web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationNumber, receipt) => { + // confirmationNumber would eqaul 1 the first time the event was emitted + // confirmationNumber would then eqaul 2 the next time + // and so on until 12 (or whatever transactionConfirmationBlocks is set to) confirmations are found +}); + +// in 4.x +web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationObject) => { + // confirmationNumber would eqaul 2 the first time the event was emitted + // confirmationNumber would then eqaul 3 the next time + // and so on until 12 (or whatever transactionConfirmationBlocks is set to) confirmations are found +}); +``` \ No newline at end of file From 2142ee80b76ca73cd40d878a3f47395810f02cdd Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Mon, 20 Jun 2022 21:42:28 +0300 Subject: [PATCH 04/18] Add more methods --- docs/docs/guides/web3_eth_migration_guide.md | 367 ++++++++++++++----- 1 file changed, 278 insertions(+), 89 deletions(-) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index 0bcf6e847f3..90e33cc074e 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -12,7 +12,7 @@ ### Defaults and Configs - `givenProvider` default value is `undefined` instead of `null` -- `currentProvider` will never return `null`, provider required upon instantiation as opposed to being optional in 1.x +- `currentProvider` will never return `null`, provider required upon instantiation as opposed to being optional in 1.x //todo maybe this is not true after after the recent discussion/change - `web3.eth.defaultAccount` default value is `undefined` instead of `null` - 1.x has `undefined` documented as default, but in implementation it's `null` - `web3.eth.defaultHardfork` default is `london` instead of `undefined` @@ -100,16 +100,16 @@ await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // '0xf ### `web3.eth.getBlock` -- Returns a hex string instead of a number for the following properties: - - `baseFeePerGas` - - `gasLimit` - - `gasUsed` - - `number` - - `size` - - `timestamp` -- Returns a hex string instead of a number string for the following properties: - - `difficulty` - - `totalDifficulty` +- Returns a hex string instead of a number for the following properties: + - `baseFeePerGas` + - `gasLimit` + - `gasUsed` + - `number` + - `size` + - `timestamp` +- Returns a hex string instead of a number string for the following properties: + - `difficulty` + - `totalDifficulty` ```typescript // in 1.x @@ -191,15 +191,15 @@ await web3.eth.getBlockUncleCount('latest'); // '0x0' ### `web3.eth.getUncle` -- Returns a hex string instead of a number for the following properties: - - `baseFeePerGas` - - `gasLimit` - - `gasUsed` - - `number` - - `size` - - `timestamp` -- Returns a hex string instead of a number string for the following properties: - - `difficulty` +- Returns a hex string instead of a number for the following properties: + - `baseFeePerGas` + - `gasLimit` + - `gasUsed` + - `number` + - `size` + - `timestamp` +- Returns a hex string instead of a number string for the following properties: + - `difficulty` ```typescript // in 1.x @@ -253,17 +253,17 @@ await web3.eth.getUncle(14965991, 0); ### `web3.eth.getTransaction` -- Returns a hex string instead of a number for the following properties: - - `blockNumber` - - `gas` - - `nonce` - - `transactionIndex` - - `type` -- Returns a hex string instead of a number string for the following properties: - - `gasPrice` - - `maxFeePerGas` - - `maxPriorityFeePerGas` - - `value` +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `gas` + - `nonce` + - `transactionIndex` + - `type` +- Returns a hex string instead of a number string for the following properties: + - `gasPrice` + - `maxFeePerGas` + - `maxPriorityFeePerGas` + - `value` ```typescript // in 1.x @@ -317,17 +317,17 @@ await web3.eth.getTransaction('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73 ### `web3.eth.getPendingTransactions` -- Returns a hex string instead of a number for the following properties: - - `blockNumber` - - `gas` - - `nonce` - - `transactionIndex` - - `type` -- Returns a hex string instead of a number string for the following properties: - - `gasPrice` - - `maxFeePerGas` - - `maxPriorityFeePerGas` - - `value` +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `gas` + - `nonce` + - `transactionIndex` + - `type` +- Returns a hex string instead of a number string for the following properties: + - `gasPrice` + - `maxFeePerGas` + - `maxPriorityFeePerGas` + - `value` ```typescript // in 1.x @@ -385,17 +385,17 @@ await web3.eth.getPendingTransactions(); ### `web3.eth.getTransactionFromBlock` -- Returns a hex string instead of a number for the following properties: - - `blockNumber` - - `gas` - - `nonce` - - `transactionIndex` - - `type` -- Returns a hex string instead of a number string for the following properties: - - `gasPrice` - - `maxFeePerGas` - - `maxPriorityFeePerGas` - - `value` +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `gas` + - `nonce` + - `transactionIndex` + - `type` +- Returns a hex string instead of a number string for the following properties: + - `gasPrice` + - `maxFeePerGas` + - `maxPriorityFeePerGas` + - `value` ```typescript // in 1.x @@ -449,18 +449,20 @@ await web3.eth.getTransactionFromBlock('latest', 1); ### `web3.eth.getTransactionReceipt` -- Returns a hex string instead of a number for the following properties: - - `blockNumber` - - `cumulativeGasUsed` - - `effectiveGasPrice` - - `gasUsed` - - `transactionIndex` -- Returns a hex string instead of a boolean for the following properties: - - `status` +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `cumulativeGasUsed` + - `effectiveGasPrice` + - `gasUsed` + - `transactionIndex` +- Returns a hex string instead of a boolean for the following properties: + - `status` ```typescript // in 1.x -await web3.eth.getTransactionReceipt('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); +await web3.eth.getTransactionReceipt( + '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +); // { // blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', // blockNumber: 14966017, @@ -479,7 +481,9 @@ await web3.eth.getTransactionReceipt('0x219f94fa188e6a0927c3c659537b5c76f4a750b9 // } // in 4.x -await web3.eth.getTransactionReceipt('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); +await web3.eth.getTransactionReceipt( + '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +); // { // blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', // blockNumber: '0xe45d01', @@ -511,14 +515,14 @@ await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe') ### `web3.eth.sendTransaction` -- `userTransactionObject.chain` no longer defaults to `mainnet`, will be `undefined` if not provided -- `userTransactionObject.hardfork` no longer defaults to `london`, will be `undefined` if not provided +- `userTransactionObject.chain` no longer defaults to `mainnet`, will be `undefined` if not provided +- `userTransactionObject.hardfork` no longer defaults to `london`, will be `undefined` if not provided #### PromiEvents ##### `sending` -- In `1.x`, this event listenter would receive a `payload` object as an arguement, in `4.x` just the sent transaction object is recieved +- In `1.x`, this event listenter would receive a `payload` object as an arguement, in `4.x` just the sent transaction object is recieved ```typescript // in 1.x @@ -553,7 +557,7 @@ web3.eth.sendTransaction({ ... }).on('sending', (sendTransactionObject) => { ... ###### `sent` -- In `1.x`, this event listenter would receive a `payload` object as an arguement, in `4.x` just the sent transaction object is recieved +- In `1.x`, this event listenter would receive a `payload` object as an arguement, in `4.x` just the sent transaction object is recieved ```typescript // in 1.x @@ -586,15 +590,15 @@ web3.eth.sendTransaction({ ... }).on('sent', (sentTransactionObject) => { ... }) ##### `receipt` -- The `receipt` object the event listener receives: - - Returns a hex string instead of a number for the following properties: - - `transactionIndex` - - `blockNumber` - - `cumulativeGasUsed` - - `gasUsed` - - `effectiveGasPrice` - - Returns a hex string instead of a boolean for the following properties: - - `status` +- The `receipt` object the event listener receives: + - Returns a hex string instead of a number for the following properties: + - `transactionIndex` + - `blockNumber` + - `cumulativeGasUsed` + - `gasUsed` + - `effectiveGasPrice` + - Returns a hex string instead of a boolean for the following properties: + - `status` ```typescript // in 1.x @@ -639,17 +643,17 @@ web3.eth.sendTransaction({ ... }).on('receipt', (receipt) => { ... }); ##### `confirmation` -- In `1.x`, this event listener would receive `confirmationNumber` and `receipt` as arguments, in `4.x` an object containing the properties: `confirmationNumber`, `receipt`, and `latestBlockHash` will be received -- `confirmationNumber` is returned as a hex string instead of a number -- For the returned `receipt` object: - - Returns a hex string instead of a number for the following properties: - - `transactionIndex` - - `blockNumber` - - `cumulativeGasUsed` - - `gasUsed` - - `effectiveGasPrice` - - Returns a hex string instead of a boolean for the following properties: - - `status` +- In `1.x`, this event listener would receive `confirmationNumber` and `receipt` as arguments, in `4.x` an object containing the properties: `confirmationNumber`, `receipt`, and `latestBlockHash` will be received +- `confirmationNumber` is returned as a hex string instead of a number +- For the returned `receipt` object: + - Returns a hex string instead of a number for the following properties: + - `transactionIndex` + - `blockNumber` + - `cumulativeGasUsed` + - `gasUsed` + - `effectiveGasPrice` + - Returns a hex string instead of a boolean for the following properties: + - `status` ```typescript // in 1.x @@ -697,7 +701,7 @@ web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationObject) => { . // } ``` -- In `1.x`, an event was emitted for each confirmation starting from `0` (the first block the transaction was included in), in `4.x` confirmations start from `1` and the first event to be emitted will have a `confirmationNumber` of `2` +- In `1.x`, an event was emitted for each confirmation starting from `0` (the first block the transaction was included in), in `4.x` confirmations start from `1` and the first event to be emitted will have a `confirmationNumber` of `2` ```typescript // in 1.x @@ -713,4 +717,189 @@ web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationObject) => { // confirmationNumber would then eqaul 3 the next time // and so on until 12 (or whatever transactionConfirmationBlocks is set to) confirmations are found }); -``` \ No newline at end of file +``` + +### `web3.eth.sendSignedTransaction` + +- Returns a hex string instead of a number for the following properties: + - `blockNumber` + - `cumulativeGasUsed` + - `effectiveGasPrice` + - `gasUsed` + - `transactionIndex` +- Returns a hex string instead of a boolean for the following properties: + - `status` + +```ts +//in 1.x +web3.eth.sendSignedTransaction({...}).then(console.log); +// { +// blockHash: '0xd2964dacbc71217cb8d58b1f3f7ac03d4abbbbd500e13bd505bbdac8361f6fae', +// blockNumber: 9, +// contractAddress: null, +// cumulativeGasUsed: 21000, +// effectiveGasPrice: 20000000000, +// from: '0xd8c375f286c258521564da00ddee3945d1d057c4', +// gasUsed: 21000, +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: true, +// to: '0x3535353535353535353535353535353535353535', +// transactionHash: '0x2bd1f369a1f9fba4b12a597761f771c34031f67584ed3c5e28a4c915ef0a1f83', +// transactionIndex: 0, +// type: '0x0' +// } + +//in 4.x +web34.eth.sendSignedTransaction({...}).then(console.log); +// { +// blockHash: '0xf433c7285366ae50334048ea2a290acc46db49abe75c5166bf71fe410834f338', +// blockNumber: '0xa', +// cumulativeGasUsed: '0x5208', +// effectiveGasPrice: '0x4a817c800', +// from: '0xd8c375f286c258521564da00ddee3945d1d057c4', +// gasUsed: '0x5208', +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: '0x1', +// to: '0x3535353535353535353535353535353535353535', +// transactionHash: '0x739c5a6593e20bd545c264482a6bb9e7aebc504559e6406a4ed2fde4bf9dad72', +// transactionIndex: '0x0', +// type: '0x0' +// } +``` + +### `web3.eth.sign` + +The message must be converted to hex first. + +```ts +//in 1.x both work +web3.eth.sign('Hello world', '0xd8c375f286c258521564da00ddee3945d1d057c4').then(console.log); +//0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c +web3.eth + .sign(web3.utils.utf8ToHex('Hello world'), '0xd8c375f286c258521564da00ddee3945d1d057c4') + .then(console.log); +//0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c + +//in 4.x message must converted beforehand +web3.eth + .sign(web3.utils.utf8ToHex('Hello world'), '0xd8c375f286c258521564da00ddee3945d1d057c4') + .then(console.log); +//0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c +``` + +### `web3.eth.signTransaction` + +- In 1.x documentation examples, the nonce seems to be optional since it isn't present in the payload, but, it is required. It is required in 4.x, too. In 1.x nonce should be a number, in 4.x it can be number or string or hex string. + +- 1.x sets gasPrice (or maxPriorityFeePerGas & maxFeePerGas) to null in EIP-1559 transactions (in not EIP-1559 transactions) in the tx object. In 4.x instead of null, they are not present. + +- In 1.x the hash of the tx is present, in 4.x not. + +```ts +//in 1.x +let payload = { + from: '0xd8c375f286c258521564da00ddee3945d1d057c4', + nonce: web3.utils.hexToNumber( + await web3.eth.getTransactionCount('0xd8c375f286c258521564da00ddee3945d1d057c4'), + ), + gasPrice: '20000000000', + gas: '21000', + to: '0x3535353535353535353535353535353535353535', + value: '1000000000000000000', + data: '', +}; + +web3.eth.signTransaction(payload).then(console.log); +// { +// raw: '0xf86e808504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080820a96a0a6dec055b314bd54c4ac294d6f298dbf8e0e4b1581d1bb916ad728ae26b55d80a01eb7b15974101a58acc6d6a976a32f058b6bdbdb2c3c4b9062865264613ef92f', +// tx: { +// type: '0x0', +// nonce: '0x0', +// gasPrice: '0x4a817c800', +// maxPriorityFeePerGas: null, +// maxFeePerGas: null, +// gas: '0x5208', +// value: '0xde0b6b3a7640000', +// input: '0x', +// v: '0xa96', +// r: '0xa6dec055b314bd54c4ac294d6f298dbf8e0e4b1581d1bb916ad728ae26b55d80', +// s: '0x1eb7b15974101a58acc6d6a976a32f058b6bdbdb2c3c4b9062865264613ef92f', +// to: '0x3535353535353535353535353535353535353535', +// hash: '0xfa45fc0923d6290ea1d0e597d81ed90d4594d82ef746eafcc36d2e4474e38fd0' +// } +// } + +//in 4.x +let payload = { + from: '0xd8c375f286c258521564da00ddee3945d1d057c4', + nonce: await web3.eth.getTransactionCount('0xd8c375f286c258521564da00ddee3945d1d057c4'), + gasPrice: '20000000000', + gas: '21000', + to: '0x3535353535353535353535353535353535353535', + value: '1000000000000000000', + data: '', +}; + +web3.eth.signTransaction(payload).then(console.log); +// raw: '0xf86e808504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080820a96a0a6dec055b314bd54c4ac294d6f298dbf8e0e4b1581d1bb916ad728ae26b55d80a01eb7b15974101a58acc6d6a976a32f058b6bdbdb2c3c4b9062865264613ef92f', +// tx: { +// type: '0x0', +// nonce: '0x0', +// gasPrice: '0x4a817c800', +// gas: '0x5208', +// value: '0xde0b6b3a7640000', +// v: '0xa96', +// r: '0xa6dec055b314bd54c4ac294d6f298dbf8e0e4b1581d1bb916ad728ae26b55d80', +// s: '0x1eb7b15974101a58acc6d6a976a32f058b6bdbdb2c3c4b9062865264613ef92f', +// to: '0x3535353535353535353535353535353535353535', +// data: '0x' +// } +// } +``` + +### `web3.eth.call` + +same as in 1.x, returns the returned data of the call + +```ts +const transaction = { + to: '0x99277D0A90F4A214c42B5B5b2c85B5ba2B46c809', + data: '0xcfae3217', +}; + +//in 1.x +web3.eth.call(transaction).then(console.log); +// 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000017736f6c79656e7420677265656e2069732070656f706c65000000000000000000 + +//in 4.x +web3.eth.call(transaction).then(console.log); +// 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000017736f6c79656e7420677265656e2069732070656f706c65000000000000000000 +``` + +### `web3.eth.estimateGas` + +returns a hex string instead of a number + +```ts +//in 1.x +web3.eth + .estimateGas({ + to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', + data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003', + }) + .then(console.log); +//21204 + +//in 4.x +web3.eth + .estimateGas({ + to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', + data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003', + }) + .then(console.log); +// 0x52d4; +``` + +### `web3.eth.getPastLogs` From 1a6a3fd206bb801b0e2aaa73af97a115b87682e2 Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Tue, 21 Jun 2022 10:30:18 +0300 Subject: [PATCH 05/18] WIP migration guide --- docs/docs/guides/web3_eth_migration_guide.md | 188 +++++++++++++++++++ 1 file changed, 188 insertions(+) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index 90e33cc074e..7661d3d4481 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -903,3 +903,191 @@ web3.eth ``` ### `web3.eth.getPastLogs` + +- Returns a hex string instead of a number for the following properties: + - `logIndex` + - `transactionIndex` + - `blockNumber` + +```ts +//in 1.x +await web3.eth + .getPastLogs({ + address: '0xE012dB5CA859A3238DdC576c0092BA5E728B7268', + topics: ['0x617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab'], + }) + .then(console.log); +// [ +// { +// address: "0xe405df0ea854cd98df9f646559ce2001396e8f5b", +// topics: [ +// "0x617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab", +// ], +// data: "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000027431000000000000000000000000000000000000000000000000000000000000", +// blockNumber: 221, +// transactionHash: +// "0xc96bbd8308f70940aa465ecdf95c7ce8c687dede5c53e5ce5ce55434c6e406bd", +// transactionIndex: 0, +// blockHash: +// "0xfd1657fc5d2b18153aa569956718cd2d3a05285712208a9544dfc093966b9c5f", +// logIndex: 0, +// removed: false, +// }, +// ]; + +//in 4.x +await web3.eth + .getPastLogs({ + address: '0xE012dB5CA859A3238DdC576c0092BA5E728B7268', + topics: ['0x617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab'], + }) + .then(console.log); +// [ +// { +// address: "0xe405df0ea854cd98df9f646559ce2001396e8f5b", +// topics: [ +// "0x617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab", +// ], +// data: "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000027431000000000000000000000000000000000000000000000000000000000000", +// blockNumber: "0xbb", +// transactionHash: +// "0xc96bbd8308f70940aa465ecdf95c7ce8c687dede5c53e5ce5ce55434c6e406bd", +// transactionIndex: "0x0", +// blockHash: +// "0xfd1657fc5d2b18153aa569956718cd2d3a05285712208a9544dfc093966b9c5f", +// logIndex: "0x0", +// removed: false, +// }, +// ]; +``` + +### `web3.eth.getWork` + +same as in 1.x // todo run example + +```ts +web3.eth.getWork().then(console.log); +// [ +// '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', +// '0x5EED00000000000000000000000000005EED0000000000000000000000000000', +// '0xd1ff1c01710000000000000000000000d1ff1c01710000000000000000000000', +// ]; +``` + +### `web3.eth.submitWork` + +same as in 1.x //todo run example + +```ts +web3.eth + .submitWork([ + '0x0000000000000001', + '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', + '0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000', + ]) + .then(console.log); +//true +``` + +### `web3.eth.requestAccouts` + +//todo add + +### `web3.eth.getChainId` + +Returns a hex string instead of a number string + +```ts +//in 1.x +web3.eth.getChainId().then(console.log); +//1337 + +//in 4.x +web3.eth.getChainId().then(console.log); +//0x539 +``` + +### `web3.eth.getNodeInfo` + +same as in 1.x + +```ts +web3.eth.getNodeInfo().then(console.log); +// Geth/v1.10.18-unstable-b3af0a55/linux-arm64/go1.18.1 +``` + +### `web3.eth.getProof` + +- Returns a hex string instead of a number string for the following properties: + - `balance` + - `nonce` + +`balance` and `nonce` in 1.x were described as numbers + +```ts +//in 1.x +web3.eth + .getProof( + '0x10d53fb7D9C9EedC40A97B51663fFd8DcC651a6b', + [ + '0x0000000000000000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000000000000000000000000000000000000000000001', + ], + 'latest', + ) + .then(console.log); +// { +// address: '0x10d53fb7D9C9EedC40A97B51663fFd8DcC651a6b', +// accountProof: [ +// '0xf90211a057107845987d38b07b52dd91268d5a41dc0c5d262feb2a21a27165387bca0447a063d1f4079378d594b3a02ac552c5d303fd0ddda203d674114468ee1908e3c61ba06e25ed79c830f5375e01e142f165f2cfd9c6c966e3755f62ae7eac87b6972dcba0e9d751f777e854f7c87fc590f20bd45d5142dd804904746fe0eec6969ef2904ca0e5eb80b4790935a22f416cbdf7abf5658c1b26d9aadcaddda80dfd30fb477605a06ebd45fd404417976368dfc3225139b9c475cd199f0e2ec9dc2bc66894c7b478a0389e57b4c2e590bd7fc4a42c5f8d1ae4f03f981c8d10fd028fe8a8cd21d4b9f6a063662eba9e6e5c1229f73d9b8123a35e837ab9b51c12bd2c21342860a850be5fa088a53f78919dddb7ec2eddb967b7d74eeab59c0352fe0a9fceeab86d3061a2aea06fec4053b58d1914ef325a74d9ad13658f19478091484935cbfb82f2ace45d07a099455c1fe3bc9c9c90668fcaf3996182b0ea32c36b16b757f877981e74265313a07afabdbb861f9c9c801a8be8b9a30fcad67b0468c1599f3150417df833b1ed15a0937108ade09abe0eb7a5d5abf7834cb4d5c6a42256071a203c97e219c9b35e4fa07333b514b144076aedef8232f460a65c5845fb7bee1dffa3d02a63d27ee103dda02a5f97f2acf28a2ef6098553188bb578f5699e5ddd86e750906427c04146638aa0b1ea877b1fb989471890e9e0eea1ca9ecabe4a501f5427dcc6122ac602ec5e5a80', +// '0xf8b1808080a01fcc2ac732952007a813f5d53b517a2f0c3b5faf38cd0654e564302e39e2fec68080a040cb340b7815612dc0705235c46f04565d5e7005b26b1544bd72d2a0cde1f7fb80a05902a1a7c70a64efedd39ed9ae25078e9054ab531c8fe4bdd7ff245ecd2bca0780a06117e0dc18ac6d32f46418eabf875a8cd21bf05b62013f87242824ca939cb776808080a0261eb1dc702fff2a022d7a2f0386224a760971187e3d6447958293f455aafbc78080', +// '0xf869a02032c2889a72d251d4f0bbf5eb448f4af962917185a86532af762ff82865ca68b846f8440180a0291bd0e0825fa92cfeb0d3b28529bae6709aa1db89a25f7e62ba5422bbb1e10ea09bbff76f89bb6a6e787eea245acb599900f2d58faab236e165e2b32df0198c84' +// ], +// balance: '0', +// codeHash: '0x9bbff76f89bb6a6e787eea245acb599900f2d58faab236e165e2b32df0198c84', +// nonce: '1', +// storageHash: '0x291bd0e0825fa92cfeb0d3b28529bae6709aa1db89a25f7e62ba5422bbb1e10e', +// storageProof: [ +// { +// key: '0x0', +// value: '0x736f6c79656e7420677265656e2069732070656f706c6500000000000000002e', +// proof: [Array] +// }, +// { key: '0x1', value: '0x0', proof: [Array] } +// ] +//} +//in 4.x +web3.eth + .getProof( + '0x10d53fb7D9C9EedC40A97B51663fFd8DcC651a6b', + [ + '0x0000000000000000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000000000000000000000000000000000000000000001', + ], + 'latest', + ) + .then(console.log); + { +// accountProof: [ +// '0xf90211a057107845987d38b07b52dd91268d5a41dc0c5d262feb2a21a27165387bca0447a063d1f4079378d594b3a02ac552c5d303fd0ddda203d674114468ee1908e3c61ba06e25ed79c830f5375e01e142f165f2cfd9c6c966e3755f62ae7eac87b6972dcba0e9d751f777e854f7c87fc590f20bd45d5142dd804904746fe0eec6969ef2904ca0e5eb80b4790935a22f416cbdf7abf5658c1b26d9aadcaddda80dfd30fb477605a06ebd45fd404417976368dfc3225139b9c475cd199f0e2ec9dc2bc66894c7b478a0389e57b4c2e590bd7fc4a42c5f8d1ae4f03f981c8d10fd028fe8a8cd21d4b9f6a063662eba9e6e5c1229f73d9b8123a35e837ab9b51c12bd2c21342860a850be5fa088a53f78919dddb7ec2eddb967b7d74eeab59c0352fe0a9fceeab86d3061a2aea06fec4053b58d1914ef325a74d9ad13658f19478091484935cbfb82f2ace45d07a099455c1fe3bc9c9c90668fcaf3996182b0ea32c36b16b757f877981e74265313a07afabdbb861f9c9c801a8be8b9a30fcad67b0468c1599f3150417df833b1ed15a0937108ade09abe0eb7a5d5abf7834cb4d5c6a42256071a203c97e219c9b35e4fa07333b514b144076aedef8232f460a65c5845fb7bee1dffa3d02a63d27ee103dda02a5f97f2acf28a2ef6098553188bb578f5699e5ddd86e750906427c04146638aa0b1ea877b1fb989471890e9e0eea1ca9ecabe4a501f5427dcc6122ac602ec5e5a80', +// '0xf8b1808080a01fcc2ac732952007a813f5d53b517a2f0c3b5faf38cd0654e564302e39e2fec68080a040cb340b7815612dc0705235c46f04565d5e7005b26b1544bd72d2a0cde1f7fb80a05902a1a7c70a64efedd39ed9ae25078e9054ab531c8fe4bdd7ff245ecd2bca0780a06117e0dc18ac6d32f46418eabf875a8cd21bf05b62013f87242824ca939cb776808080a0261eb1dc702fff2a022d7a2f0386224a760971187e3d6447958293f455aafbc78080', +// '0xf869a02032c2889a72d251d4f0bbf5eb448f4af962917185a86532af762ff82865ca68b846f8440180a0291bd0e0825fa92cfeb0d3b28529bae6709aa1db89a25f7e62ba5422bbb1e10ea09bbff76f89bb6a6e787eea245acb599900f2d58faab236e165e2b32df0198c84' +// ], +// balance: '0x0', +// codeHash: '0x9bbff76f89bb6a6e787eea245acb599900f2d58faab236e165e2b32df0198c84', +// nonce: '0x1', +// storageHash: '0x291bd0e0825fa92cfeb0d3b28529bae6709aa1db89a25f7e62ba5422bbb1e10e', +// storageProof: [ +// { +// key: '0x0000000000000000000000000000000000000000000000000000000000000000', +// value: '0x736f6c79656e7420677265656e2069732070656f706c6500000000000000002e', +// proof: [Array] +// }, +// { +// key: '0x0000000000000000000000000000000000000000000000000000000000000001', +// value: '0x0', +// proof: [Array] +// } +// ] +// } +``` From 58612414b0a76376e68dcfb8e97d7e297c695813 Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Tue, 21 Jun 2022 13:25:46 +0300 Subject: [PATCH 06/18] Add request accounts --- docs/docs/guides/web3_eth_migration_guide.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index 7661d3d4481..ddc907e8df3 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -963,7 +963,7 @@ await web3.eth ### `web3.eth.getWork` -same as in 1.x // todo run example +same as in 1.x ```ts web3.eth.getWork().then(console.log); @@ -976,7 +976,7 @@ web3.eth.getWork().then(console.log); ### `web3.eth.submitWork` -same as in 1.x //todo run example +same as in 1.x ```ts web3.eth @@ -991,7 +991,12 @@ web3.eth ### `web3.eth.requestAccouts` -//todo add +same as 1.x, returns array of addressed (must be used with injected provider) + +```ts +await web3.eth.requestAccounts(); +//['0xb839Aa3ECdd24c0Fa2fa382Ca179b88a0b33804f'] +``` ### `web3.eth.getChainId` From fe134eb56f64f0735f87088ead06ef866599a5c0 Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Mon, 27 Jun 2022 14:56:08 +0300 Subject: [PATCH 07/18] Apply some changes from reviews --- docs/docs/guides/web3_eth_migration_guide.md | 110 ++++++++++--------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index ddc907e8df3..9e5ae083b89 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -2,6 +2,8 @@ ## Breaking Changes +Any function which returned `number` value, now returns `bigint` + ### Not Implemented or Exported - [extend](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#extend) functionality not implemented @@ -28,14 +30,14 @@ renamed to `getHashRate` ### `web3.eth.getGasPrice` -returns a hex string instead of a number string +returns a bigint string instead of a number string ```typescript // in 1.x await web3.eth.getGasPrice(); // '2000000000' // in 4.x -await web3.eth.getGasPrice(); // '0x77359400' +await web3.eth.getGasPrice(); // 2000000000n ``` ### `web3.eth.getFeeHistory` @@ -76,14 +78,14 @@ await web3.eth.getAccounts(); ### `web3.eth.getBlockNumber` -returns a hex string instead of a number +returns a bigint instead of a number ```typescript // in 1.x await web3.eth.getBlockNumber(); // 0 // in 4.x -await web3.eth.getBlockNumber(); // '0x0' +await web3.eth.getBlockNumber(); // '0n' ``` ### `web3.eth.getBalance` @@ -92,22 +94,22 @@ returns a hex string instead of a number string ```typescript // in 1.x -await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // '115792089237316195423570985008687907853269984665640564039457584007913129639927' +await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // '115792089237316195423570985008687907853269984665640564039357583989538129639927' // in 4.x -await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7' +await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // 115792089237316195423570985008687907853269984665640564039357583989538129639927n ``` ### `web3.eth.getBlock` -- Returns a hex string instead of a number for the following properties: +- Returns a bigint instead of a number for the following properties: - `baseFeePerGas` - `gasLimit` - `gasUsed` - `number` - `size` - `timestamp` -- Returns a hex string instead of a number string for the following properties: +- Returns a bigint instead of a number string for the following properties: - `difficulty` - `totalDifficulty` @@ -115,66 +117,70 @@ await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // '0xf // in 1.x await web3.eth.getBlock('latest'); // { -// baseFeePerGas: 1000000000, -// difficulty: '1', -// extraData: '0x0000000000000000000000000000000000000000000000000000000000000000ab089b30f46883c3598b720d85837080b9929d0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// gasLimit: 11500000, -// gasUsed: 0, -// hash: '0x898f2ec817477ef26f0f84e4070840ca9f020fdc2fd4c0375df051da96b93045', -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// miner: '0x0000000000000000000000000000000000000000', -// mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', -// nonce: '0x0000000000000000', -// number: 0, -// parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', -// receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', -// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -// size: 627, -// stateRoot: '0xcdbd36dbc4916d258879c5d4fccfc54c6dc0cbd39a6dba5be19e09f4b8e6587d', -// timestamp: 0, -// totalDifficulty: '1', -// transactions: [], -// transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', -// uncles: [] +// baseFeePerGas: 875000000, +// difficulty: '2', +// extraData: '0xd883010a12846765746888676f312e31382e31856c696e75780000000000000010157d9c4ad322d920918d4ddae4e001202a22839fbfd2371b1ddf285300e9e9594b411a7fac32c9bb8a46d2a91d6070ccb3aad2f2e868e0c1ea63f704312eba00', +// gasLimit: 11511229, +// gasUsed: 21000, +// hash: '0x784c14e4f4593cf26a8351a60bf638005ba5f9484bf10cfdd91efa111b374d66', +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// miner: '0x0000000000000000000000000000000000000000', +// mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', +// nonce: '0x0000000000000000', +// number: 1, +// parentHash: '0x9652fad2b90eb0e77c7ef0aca9d906ab75af9c43f82351e7dac910ee8621fff4', +// receiptsRoot: '0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2', +// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', +// size: 725, +// stateRoot: '0xbfcc9c1696039dbfb95250cf36a43bbc07e1fce54d6d0c000cb38a8a77038660', +// timestamp: 1656322892, +// totalDifficulty: '3', +// transactions: [ +// '0x7de9d0e0082eaa351466f5919bb17b42263a2cbe132064eb551dcc9d134b5df8' +// ], +// transactionsRoot: '0x806f860d591e93723afa2e16f8cce628bd02acbf03325dcab76b9a7c7012c535', +// uncles: [] // } // in 4.x await web3.eth.getBlock('latest'); // { -// baseFeePerGas: '0x3b9aca00', -// difficulty: '0x1', -// extraData: '0x0000000000000000000000000000000000000000000000000000000000000000ab089b30f46883c3598b720d85837080b9929d0b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// gasLimit: '0xaf79e0', -// gasUsed: '0x0', -// hash: '0x898f2ec817477ef26f0f84e4070840ca9f020fdc2fd4c0375df051da96b93045', -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// miner: '0x0000000000000000000000000000000000000000', -// mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', -// nonce: '0x0', -// number: '0x0', -// parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', -// receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', -// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -// size: '0x273', -// stateRoot: '0xcdbd36dbc4916d258879c5d4fccfc54c6dc0cbd39a6dba5be19e09f4b8e6587d', -// timestamp: '0x0', -// totalDifficulty: '0x1', -// transactions: [], -// transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', -// uncles: [] +// baseFeePerGas: 875000000n, +// difficulty: 2n, +// extraData: '0xd883010a12846765746888676f312e31382e31856c696e75780000000000000010157d9c4ad322d920918d4ddae4e001202a22839fbfd2371b1ddf285300e9e9594b411a7fac32c9bb8a46d2a91d6070ccb3aad2f2e868e0c1ea63f704312eba00', +// gasLimit: 11511229n, +// gasUsed: 21000n, +// hash: '0x784c14e4f4593cf26a8351a60bf638005ba5f9484bf10cfdd91efa111b374d66', +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// miner: '0x0000000000000000000000000000000000000000', +// mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', +// nonce: 0n, +// number: 1n, +// parentHash: '0x9652fad2b90eb0e77c7ef0aca9d906ab75af9c43f82351e7dac910ee8621fff4', +// receiptsRoot: '0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2', +// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', +// size: 725n, +// stateRoot: '0xbfcc9c1696039dbfb95250cf36a43bbc07e1fce54d6d0c000cb38a8a77038660', +// timestamp: 1656322892n, +// totalDifficulty: 3n, +// transactions: [ +// '0x7de9d0e0082eaa351466f5919bb17b42263a2cbe132064eb551dcc9d134b5df8' +// ], +// transactionsRoot: '0x806f860d591e93723afa2e16f8cce628bd02acbf03325dcab76b9a7c7012c535', +// uncles: [] // } ``` ### `web3.eth.getBlockTransactionCount` -returns a hex string instead of a number +returns a bigint instead of a number ```typescript // in 1.x await web3.eth.getBlockTransactionCount('latest'); // 0 // in 4.x -await web3.eth.getBlockTransactionCount('latest'); // '0x0' +await web3.eth.getBlockTransactionCount('latest'); // 0n ``` ### `web3.eth.getBlockUncleCount` From f131ff868a1641fc1d39a7453221fe364a424d31 Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Mon, 27 Jun 2022 16:27:05 +0300 Subject: [PATCH 08/18] Add getHashrate as deprecated --- packages/web3-eth/src/web3_eth.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/web3-eth/src/web3_eth.ts b/packages/web3-eth/src/web3_eth.ts index 0bb59953c82..135bf303eac 100644 --- a/packages/web3-eth/src/web3_eth.ts +++ b/packages/web3-eth/src/web3_eth.ts @@ -109,6 +109,13 @@ export class Web3Eth extends Web3Context( returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat, ) { From 8a1a36eb3f71d7ca54a7b12dae31d19cb44e752f Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Mon, 27 Jun 2022 16:43:57 +0300 Subject: [PATCH 09/18] Remove getAccounts, as it will be fixed --- docs/docs/guides/web3_eth_migration_guide.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index 9e5ae083b89..dca47fcee62 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -62,20 +62,6 @@ await web3.eth.getFeeHistory('0x1', 'latest', []); // } ``` -### `web3.eth.getAccounts` - -addresses are not returned as checksum - -```typescript -// in 1.x -await web3.eth.getAccounts(); -// ['0xAB089B30f46883C3598B720d85837080b9929D0B'] - -// in 4.x -await web3.eth.getAccounts(); -// ['0xab089b30f46883c3598b720d85837080b9929d0b'] -``` - ### `web3.eth.getBlockNumber` returns a bigint instead of a number From 8608beb76338f9488c3be224ca30dbbbc7c50690 Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Mon, 27 Jun 2022 18:15:47 +0300 Subject: [PATCH 10/18] Fix hex string to bigint in docs --- docs/docs/guides/web3_eth_migration_guide.md | 240 ++++++++++--------- 1 file changed, 121 insertions(+), 119 deletions(-) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index dca47fcee62..4fc39c0ec34 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -4,19 +4,21 @@ Any function which returned `number` value, now returns `bigint` +All the API level interfaces returning or accepting `null` in 1.x, use `undefined` now + ### Not Implemented or Exported - [extend](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#extend) functionality not implemented -- [web3.eth.createAccessList](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#createaccesslist) not implemented -- [web3.eth.personal](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#personal) namespace is not exported -- [web3.eth.net](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#net) namespace is not exported ### Defaults and Configs -- `givenProvider` default value is `undefined` instead of `null` -- `currentProvider` will never return `null`, provider required upon instantiation as opposed to being optional in 1.x //todo maybe this is not true after after the recent discussion/change -- `web3.eth.defaultAccount` default value is `undefined` instead of `null` - - 1.x has `undefined` documented as default, but in implementation it's `null` +- All default values that returned `null` in 1.x, in 4.x return `undefined`. There are: + + - `givenProvider` + - `currentProvider` + - `web3.eth.defaultAccount` + - 1.x has `undefined` documented as default, but in implementation it's `null` + - `web3.eth.defaultHardfork` default is `london` instead of `undefined` - 1.x has `london` documented as default, but in implementation it's `undefined` - `web3.eth.defaultChain` default is `mainnet` instead of `undefined` @@ -26,7 +28,7 @@ Any function which returned `number` value, now returns `bigint` ### `web3.eth.getHashrate` -renamed to `getHashRate` +`getHashrate` is deprecated, and will be removed in a future release. Please use `getHashRate` ### `web3.eth.getGasPrice` @@ -42,7 +44,7 @@ await web3.eth.getGasPrice(); // 2000000000n ### `web3.eth.getFeeHistory` -returns hex strings for `gasUsedRation` array items instead of a numbers +returns hex strings for `gasUsedRatio` array items instead of a numbers ```typescript // in 1.x @@ -76,7 +78,7 @@ await web3.eth.getBlockNumber(); // '0n' ### `web3.eth.getBalance` -returns a hex string instead of a number string +returns a bigint instead of a number string ```typescript // in 1.x @@ -171,26 +173,26 @@ await web3.eth.getBlockTransactionCount('latest'); // 0n ### `web3.eth.getBlockUncleCount` -returns a hex string instead of a number +returns a bigint instead of a number ```typescript // in 1.x await web3.eth.getBlockUncleCount('latest'); // 0 // in 4.x -await web3.eth.getBlockUncleCount('latest'); // '0x0' +await web3.eth.getBlockUncleCount('latest'); // '0' ``` ### `web3.eth.getUncle` -- Returns a hex string instead of a number for the following properties: +- Returns a bigint instead of a number for the following properties: - `baseFeePerGas` - `gasLimit` - `gasUsed` - `number` - `size` - `timestamp` -- Returns a hex string instead of a number string for the following properties: +- Returns a bigint instead of a number string for the following properties: - `difficulty` ```typescript @@ -245,17 +247,18 @@ await web3.eth.getUncle(14965991, 0); ### `web3.eth.getTransaction` -- Returns a hex string instead of a number for the following properties: +- Returns a bigint instead of a number for the following properties: - `blockNumber` - `gas` - `nonce` - `transactionIndex` - `type` -- Returns a hex string instead of a number string for the following properties: +- Returns a bigint instead of a number string for the following properties: - `gasPrice` - `maxFeePerGas` - `maxPriorityFeePerGas` - `value` + - `chainId` ```typescript // in 1.x @@ -285,37 +288,37 @@ await web3.eth.getTransaction('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73 // in 4.x await web3.eth.getTransaction('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); // { -// accessList: [], -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: '0xe45d01', -// chainId: '0x1', -// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', -// gas: '0x5208', -// gasPrice: '0x743b079cd', -// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// input: '0x', -// maxFeePerGas: '0xd13321d0d', -// maxPriorityFeePerGas: '0x59682f00', -// nonce: '0x110', -// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', -// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', -// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', -// transactionIndex: '0x50', -// type: '0x2', -// v: '0x1', -// value: '0x2e6c563ada1ff8' +// accessList: [], +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: 14966017n, +// chainId: 1n, +// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', +// gas: 21000n, +// gasPrice: 31200410061n, +// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// input: '0x', +// maxFeePerGas: 56156626189n, +// maxPriorityFeePerGas: 1500000000n, +// nonce: 272n, +// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', +// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', +// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', +// transactionIndex: 80n, +// type: 2n, +// v: 1n, +// value: 13066966539051000n // } ``` ### `web3.eth.getPendingTransactions` -- Returns a hex string instead of a number for the following properties: +- Returns a bigint instead of a number for the following properties: - `blockNumber` - `gas` - `nonce` - `transactionIndex` - `type` -- Returns a hex string instead of a number string for the following properties: +- Returns a bigint instead of a number string for the following properties: - `gasPrice` - `maxFeePerGas` - `maxPriorityFeePerGas` @@ -328,23 +331,23 @@ await web3.eth.getPendingTransactions(); // { // accessList: [], // blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: 14966017, -// chainId: '0x1', +// blockNumber: 14966017n, +// chainId: 1n, // from: '0x3b7414bE92e87837D6f95D01B8E3c93aC9D20804', -// gas: 21000, -// gasPrice: '31200410061', +// gas: 21000n, +// gasPrice: '31200410061n', // hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', // input: '0x', -// maxFeePerGas: '56156626189', -// maxPriorityFeePerGas: '1500000000', -// nonce: 272, +// maxFeePerGas: 56156626189n, +// maxPriorityFeePerGas: 1500000000n, +// nonce: 272n, // r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', // s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', // to: '0x8b664E252B7c5C87c17e73C69F16E56454C9661F', -// transactionIndex: 80, -// type: 2, +// transactionIndex: 80n, +// type: 2n, // v: '0x1', -// value: '13066966539051000' +// value: 13066966539051000n // }, // ...] @@ -377,13 +380,13 @@ await web3.eth.getPendingTransactions(); ### `web3.eth.getTransactionFromBlock` -- Returns a hex string instead of a number for the following properties: +- Returns a bigint instead of a number for the following properties: - `blockNumber` - `gas` - `nonce` - `transactionIndex` - `type` -- Returns a hex string instead of a number string for the following properties: +- Returns a bigint instead of a number string for the following properties: - `gasPrice` - `maxFeePerGas` - `maxPriorityFeePerGas` @@ -419,35 +422,35 @@ await web3.eth.getTransactionFromBlock('latest', 1); // { // accessList: [], // blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: '0xe45d01', -// chainId: '0x1', +// blockNumber: 0xe45d01n, +// chainId: 1n, // from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', -// gas: '0x5208', -// gasPrice: '0x743b079cd', +// gas: 5208n, +// gasPrice: 0x743b079cdn, // hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', // input: '0x', -// maxFeePerGas: '0xd13321d0d', -// maxPriorityFeePerGas: '0x59682f00', -// nonce: '0x110', +// maxFeePerGas: d13321d0dn, +// maxPriorityFeePerGas: 59682f00n, +// nonce: 110n, // r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', // s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', // to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', -// transactionIndex: '0x50', -// type: '0x2', +// transactionIndex: 50n, +// type: 2n, // v: '0x1', -// value: '0x2e6c563ada1ff8' +// value: 2e6c563ada1ff8n // } ``` ### `web3.eth.getTransactionReceipt` -- Returns a hex string instead of a number for the following properties: +- Returns a bigint instead of a number for the following properties: - `blockNumber` - `cumulativeGasUsed` - `effectiveGasPrice` - `gasUsed` - `transactionIndex` -- Returns a hex string instead of a boolean for the following properties: +- Returns a bigint instead of a boolean for the following properties: - `status` ```typescript @@ -477,32 +480,32 @@ await web3.eth.getTransactionReceipt( '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', ); // { -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: '0xe45d01', -// cumulativeGasUsed: '0x6ab1fe', -// effectiveGasPrice: '0x743b079cd', -// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', -// gasUsed: '0x5208', -// logs: [], -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// status: '0x1', -// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', -// transactionHash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// transactionIndex: '0x50', -// type: '0x2' +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: 14966017n, +// cumulativeGasUsed: 6992382n, +// effectiveGasPrice: 31200410061n, +// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', +// gasUsed: 21000n, +// logs: [], +// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', +// status: 1n, +// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', +// transactionHash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// transactionIndex: 80n, +// type: 2n // } ``` ### `web3.eth.getTransactionCount` -returns a hex string instead of a number +returns a bigint instead of a number ```typescript // in 1.x await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); // 0 // in 4.x -await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); // '0x0' +await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); // 0n ``` ### `web3.eth.sendTransaction` @@ -583,13 +586,13 @@ web3.eth.sendTransaction({ ... }).on('sent', (sentTransactionObject) => { ... }) ##### `receipt` - The `receipt` object the event listener receives: - - Returns a hex string instead of a number for the following properties: + - Returns a bigint instead of a number for the following properties: - `transactionIndex` - `blockNumber` - `cumulativeGasUsed` - `gasUsed` - `effectiveGasPrice` - - Returns a hex string instead of a boolean for the following properties: + - Returns a bigint instead of a boolean for the following properties: - `status` ```typescript @@ -597,20 +600,19 @@ web3.eth.sendTransaction({ ... }).on('sent', (sentTransactionObject) => { ... }) web3.eth.sendTransaction({ ... }).on('receipt', (receipt) => { ... }); // receipt would be: // { -// transactionHash: '0x4f0f428ae3c2f0ec5e054491ecf01a0c38b92ef128350d4831c07ef52f5d4a15', -// transactionIndex: 0, -// blockNumber: 14, -// blockHash: '0x5bb7c47a0fcb8d53fc2d1524873631340c1855c7b98d657de614d4d0554596f8', -// from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', -// to: '0x0000000000000000000000000000000000000000', -// cumulativeGasUsed: 21000, -// gasUsed: 21000, -// contractAddress: null, +// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', +// blockNumber: 14966017n, +// cumulativeGasUsed: 6992382n, +// effectiveGasPrice: 31200410061n, +// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', +// gasUsed: 21000n, // logs: [], // logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// status: true, -// effectiveGasPrice: 2654611504, -// type: '0x2' +// status: 1n, +// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', +// transactionHash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', +// transactionIndex: 80n, +// type: 2n // } // in 4.x @@ -636,15 +638,15 @@ web3.eth.sendTransaction({ ... }).on('receipt', (receipt) => { ... }); ##### `confirmation` - In `1.x`, this event listener would receive `confirmationNumber` and `receipt` as arguments, in `4.x` an object containing the properties: `confirmationNumber`, `receipt`, and `latestBlockHash` will be received -- `confirmationNumber` is returned as a hex string instead of a number +- `confirmationNumber` is returned as a bigint instead of a number - For the returned `receipt` object: - - Returns a hex string instead of a number for the following properties: + - Returns a bigint instead of a number for the following properties: - `transactionIndex` - `blockNumber` - `cumulativeGasUsed` - `gasUsed` - `effectiveGasPrice` - - Returns a hex string instead of a boolean for the following properties: + - Returns a bigint instead of a boolean for the following properties: - `status` ```typescript @@ -673,20 +675,20 @@ web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationNumber, receip web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationObject) => { ... }); // confirmationObject would have the following structure: // { -// confirmationNumber: '0x2', +// confirmationNumber: 2n, // receipt: { // transactionHash: '0xd93fe25c2066cd8f15565bcff693507a3c70f5fb9387db57f939ae91f4080c6c', -// transactionIndex: '0x0', -// blockNumber: '0x5', +// transactionIndex: 0n, +// blockNumber: 5n, // blockHash: '0xe1775977a8041cb2709136804e4be609135f8367b49d38960f92a95b4c02189a', // from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', // to: '0x0000000000000000000000000000000000000000', -// cumulativeGasUsed: '0x5208', -// gasUsed: '0x5208', +// cumulativeGasUsed: 5208n, +// gasUsed: 5208n, // logs: [], // logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// status: '0x1', -// effectiveGasPrice: '0x77359400', +// status: 1n, +// effectiveGasPrice: 77359400n, // type: '0x0' // }, // latestBlockHash: '0xb2ef3763190da82d8efa938f73efa5bb21e3d95c2ce25dd38ca21eea1a942260' @@ -713,13 +715,13 @@ web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationObject) => { ### `web3.eth.sendSignedTransaction` -- Returns a hex string instead of a number for the following properties: +- Returns a bigint instead of a number for the following properties: - `blockNumber` - `cumulativeGasUsed` - `effectiveGasPrice` - `gasUsed` - `transactionIndex` -- Returns a hex string instead of a boolean for the following properties: +- Returns a bigint instead of a boolean for the following properties: - `status` ```ts @@ -746,17 +748,17 @@ web3.eth.sendSignedTransaction({...}).then(console.log); web34.eth.sendSignedTransaction({...}).then(console.log); // { // blockHash: '0xf433c7285366ae50334048ea2a290acc46db49abe75c5166bf71fe410834f338', -// blockNumber: '0xa', -// cumulativeGasUsed: '0x5208', -// effectiveGasPrice: '0x4a817c800', +// blockNumber: 10n, +// cumulativeGasUsed: 21000n, +// effectiveGasPrice: 20000000000n, // from: '0xd8c375f286c258521564da00ddee3945d1d057c4', -// gasUsed: '0x5208', +// gasUsed: 21000n, // logs: [], // logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// status: '0x1', +// status: 1n, // to: '0x3535353535353535353535353535353535353535', // transactionHash: '0x739c5a6593e20bd545c264482a6bb9e7aebc504559e6406a4ed2fde4bf9dad72', -// transactionIndex: '0x0', +// transactionIndex: 0n, // type: '0x0' // } ``` @@ -872,7 +874,7 @@ web3.eth.call(transaction).then(console.log); ### `web3.eth.estimateGas` -returns a hex string instead of a number +returns a bigint instead of a number ```ts //in 1.x @@ -891,12 +893,12 @@ web3.eth data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003', }) .then(console.log); -// 0x52d4; +//21204n ``` ### `web3.eth.getPastLogs` -- Returns a hex string instead of a number for the following properties: +- Returns a bigint instead of a number for the following properties: - `logIndex` - `transactionIndex` - `blockNumber` @@ -941,13 +943,13 @@ await web3.eth // "0x617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab", // ], // data: "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000027431000000000000000000000000000000000000000000000000000000000000", -// blockNumber: "0xbb", +// blockNumber: 221n, // transactionHash: // "0xc96bbd8308f70940aa465ecdf95c7ce8c687dede5c53e5ce5ce55434c6e406bd", -// transactionIndex: "0x0", +// transactionIndex: 0n, // blockHash: // "0xfd1657fc5d2b18153aa569956718cd2d3a05285712208a9544dfc093966b9c5f", -// logIndex: "0x0", +// logIndex: 0n, // removed: false, // }, // ]; @@ -992,7 +994,7 @@ await web3.eth.requestAccounts(); ### `web3.eth.getChainId` -Returns a hex string instead of a number string +Returns a bigint instead of a number string ```ts //in 1.x @@ -1001,7 +1003,7 @@ web3.eth.getChainId().then(console.log); //in 4.x web3.eth.getChainId().then(console.log); -//0x539 +//1337n ``` ### `web3.eth.getNodeInfo` @@ -1015,7 +1017,7 @@ web3.eth.getNodeInfo().then(console.log); ### `web3.eth.getProof` -- Returns a hex string instead of a number string for the following properties: +- Returns a bigint instead of a number string for the following properties: - `balance` - `nonce` @@ -1070,9 +1072,9 @@ web3.eth // '0xf8b1808080a01fcc2ac732952007a813f5d53b517a2f0c3b5faf38cd0654e564302e39e2fec68080a040cb340b7815612dc0705235c46f04565d5e7005b26b1544bd72d2a0cde1f7fb80a05902a1a7c70a64efedd39ed9ae25078e9054ab531c8fe4bdd7ff245ecd2bca0780a06117e0dc18ac6d32f46418eabf875a8cd21bf05b62013f87242824ca939cb776808080a0261eb1dc702fff2a022d7a2f0386224a760971187e3d6447958293f455aafbc78080', // '0xf869a02032c2889a72d251d4f0bbf5eb448f4af962917185a86532af762ff82865ca68b846f8440180a0291bd0e0825fa92cfeb0d3b28529bae6709aa1db89a25f7e62ba5422bbb1e10ea09bbff76f89bb6a6e787eea245acb599900f2d58faab236e165e2b32df0198c84' // ], -// balance: '0x0', +// balance: 0n, // codeHash: '0x9bbff76f89bb6a6e787eea245acb599900f2d58faab236e165e2b32df0198c84', -// nonce: '0x1', +// nonce: 1n, // storageHash: '0x291bd0e0825fa92cfeb0d3b28529bae6709aa1db89a25f7e62ba5422bbb1e10e', // storageProof: [ // { From 5f7c76533621e3c989ed44d459f6fe6a8a3706b4 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Thu, 7 Jul 2022 19:18:55 -1000 Subject: [PATCH 11/18] Migration guide refactors --- docs/docs/guides/web3_eth_migration_guide.md | 829 +++++-------------- 1 file changed, 219 insertions(+), 610 deletions(-) diff --git a/docs/docs/guides/web3_eth_migration_guide.md b/docs/docs/guides/web3_eth_migration_guide.md index 4fc39c0ec34..4a88a6cebb7 100644 --- a/docs/docs/guides/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_eth_migration_guide.md @@ -1,511 +1,160 @@ -# Web3Eth Migration Guide +# Web3.eth Migration Guide ## Breaking Changes -Any function which returned `number` value, now returns `bigint` +All the API level interfaces returning or accepting `null` in `1.x`, use `undefined` in `4.x` -All the API level interfaces returning or accepting `null` in 1.x, use `undefined` now +### Return Values -### Not Implemented or Exported +##### Returns a `BigInt` instead of a number string -- [extend](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#extend) functionality not implemented - -### Defaults and Configs - -- All default values that returned `null` in 1.x, in 4.x return `undefined`. There are: - - - `givenProvider` - - `currentProvider` - - `web3.eth.defaultAccount` - - 1.x has `undefined` documented as default, but in implementation it's `null` +- `web3.eth.getGasPrice` +- `web3.eth.getBalance` -- `web3.eth.defaultHardfork` default is `london` instead of `undefined` - - 1.x has `london` documented as default, but in implementation it's `undefined` -- `web3.eth.defaultChain` default is `mainnet` instead of `undefined` - - 1.x has `mainnet` documented as default, but in implementation it's `undefined` +##### Returns a `BigInt` instead of a number -### Web3Eth Methods - -### `web3.eth.getHashrate` +- `web3.eth.getBlockNumber` +- `web3.eth.getBlockTransactionCount` +- `web3.eth.getBlockUncleCount` +- `web3.eth.getTransactionCount` +- `web3.eth.estimateGas` -`getHashrate` is deprecated, and will be removed in a future release. Please use `getHashRate` +--- -### `web3.eth.getGasPrice` +##### `web3.eth.getBlock` -returns a bigint string instead of a number string - -```typescript -// in 1.x -await web3.eth.getGasPrice(); // '2000000000' - -// in 4.x -await web3.eth.getGasPrice(); // 2000000000n -``` - -### `web3.eth.getFeeHistory` - -returns hex strings for `gasUsedRatio` array items instead of a numbers - -```typescript -// in 1.x -await web3.eth.getFeeHistory('0x1', 'latest', []); -// { -// oldestBlock: '0x0', -// baseFeePerGas: [ '0x3b9aca00', '0x342770c0' ], -// gasUsedRatio: [ 0 ] -// } - -// in 4.x -await web3.eth.getFeeHistory('0x1', 'latest', []); -// { -// oldestBlock: '0x0', -// baseFeePerGas: [ '0x3b9aca00', '0x342770c0' ], -// gasUsedRatio: [ '0x0' ] -// } -``` - -### `web3.eth.getBlockNumber` - -returns a bigint instead of a number - -```typescript -// in 1.x -await web3.eth.getBlockNumber(); // 0 - -// in 4.x -await web3.eth.getBlockNumber(); // '0n' -``` - -### `web3.eth.getBalance` - -returns a bigint instead of a number string - -```typescript -// in 1.x -await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // '115792089237316195423570985008687907853269984665640564039357583989538129639927' - -// in 4.x -await web3.eth.getBalance('0xAB089B30f46883C3598B720d85837080b9929D0B'); // 115792089237316195423570985008687907853269984665640564039357583989538129639927n -``` - -### `web3.eth.getBlock` - -- Returns a bigint instead of a number for the following properties: +- Returns a `BigInt` instead of a number for the following properties: - `baseFeePerGas` - `gasLimit` - `gasUsed` - `number` - `size` - `timestamp` -- Returns a bigint instead of a number string for the following properties: +- Returns a `BigInt` instead of a number string for the following properties: - `difficulty` - `totalDifficulty` -```typescript -// in 1.x -await web3.eth.getBlock('latest'); -// { -// baseFeePerGas: 875000000, -// difficulty: '2', -// extraData: '0xd883010a12846765746888676f312e31382e31856c696e75780000000000000010157d9c4ad322d920918d4ddae4e001202a22839fbfd2371b1ddf285300e9e9594b411a7fac32c9bb8a46d2a91d6070ccb3aad2f2e868e0c1ea63f704312eba00', -// gasLimit: 11511229, -// gasUsed: 21000, -// hash: '0x784c14e4f4593cf26a8351a60bf638005ba5f9484bf10cfdd91efa111b374d66', -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// miner: '0x0000000000000000000000000000000000000000', -// mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', -// nonce: '0x0000000000000000', -// number: 1, -// parentHash: '0x9652fad2b90eb0e77c7ef0aca9d906ab75af9c43f82351e7dac910ee8621fff4', -// receiptsRoot: '0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2', -// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -// size: 725, -// stateRoot: '0xbfcc9c1696039dbfb95250cf36a43bbc07e1fce54d6d0c000cb38a8a77038660', -// timestamp: 1656322892, -// totalDifficulty: '3', -// transactions: [ -// '0x7de9d0e0082eaa351466f5919bb17b42263a2cbe132064eb551dcc9d134b5df8' -// ], -// transactionsRoot: '0x806f860d591e93723afa2e16f8cce628bd02acbf03325dcab76b9a7c7012c535', -// uncles: [] -// } - -// in 4.x -await web3.eth.getBlock('latest'); -// { -// baseFeePerGas: 875000000n, -// difficulty: 2n, -// extraData: '0xd883010a12846765746888676f312e31382e31856c696e75780000000000000010157d9c4ad322d920918d4ddae4e001202a22839fbfd2371b1ddf285300e9e9594b411a7fac32c9bb8a46d2a91d6070ccb3aad2f2e868e0c1ea63f704312eba00', -// gasLimit: 11511229n, -// gasUsed: 21000n, -// hash: '0x784c14e4f4593cf26a8351a60bf638005ba5f9484bf10cfdd91efa111b374d66', -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// miner: '0x0000000000000000000000000000000000000000', -// mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', -// nonce: 0n, -// number: 1n, -// parentHash: '0x9652fad2b90eb0e77c7ef0aca9d906ab75af9c43f82351e7dac910ee8621fff4', -// receiptsRoot: '0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2', -// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -// size: 725n, -// stateRoot: '0xbfcc9c1696039dbfb95250cf36a43bbc07e1fce54d6d0c000cb38a8a77038660', -// timestamp: 1656322892n, -// totalDifficulty: 3n, -// transactions: [ -// '0x7de9d0e0082eaa351466f5919bb17b42263a2cbe132064eb551dcc9d134b5df8' -// ], -// transactionsRoot: '0x806f860d591e93723afa2e16f8cce628bd02acbf03325dcab76b9a7c7012c535', -// uncles: [] -// } -``` - -### `web3.eth.getBlockTransactionCount` - -returns a bigint instead of a number - -```typescript -// in 1.x -await web3.eth.getBlockTransactionCount('latest'); // 0 - -// in 4.x -await web3.eth.getBlockTransactionCount('latest'); // 0n -``` - -### `web3.eth.getBlockUncleCount` +##### `web3.eth.getUncle` -returns a bigint instead of a number - -```typescript -// in 1.x -await web3.eth.getBlockUncleCount('latest'); // 0 - -// in 4.x -await web3.eth.getBlockUncleCount('latest'); // '0' -``` - -### `web3.eth.getUncle` - -- Returns a bigint instead of a number for the following properties: +- Returns a `BigInt` instead of a number for the following properties: - `baseFeePerGas` - `gasLimit` - `gasUsed` - `number` - `size` - `timestamp` -- Returns a bigint instead of a number string for the following properties: +- Returns a `BigInt` instead of a number string for the following properties: - `difficulty` -```typescript -// in 1.x -await web3.eth.getUncle(14965991, 0); -// { -// baseFeePerGas: 35571562105, -// difficulty: '13923582981852799', -// extraData: '0x617369612d65617374322d3132', -// gasLimit: 30087829, -// gasUsed: 11487217, -// hash: '0xf049e44dba7ae7c45239de3e2264ead7abd86fec3399ae2234edf778e936885c', -// logsBloom: '0x206cab47e94018b154281022c05863330003318c70a0ca4460244b4134a88517302d93c854b8068110a11b1342212335ba2020000d12fc330a44489e013e20149006f2034180105e7a820219b52861a241a210ca8d50385d3c481c21a8406c509a584cb15a226e0620111a884c262b9236010cf444700c030e2480f7200a6484b22b15a012c29903b40c0cc4830304c665003cc1b1b240b8752087d8ea1261e2ef8e293711c26d3b2b87c0988dd928d2d1a427340a90900641270ea6008a4d10032424ef0c0209789b424b4c304f5a0700640a40dfae02506303396e85182021203170182904980140409004cde41f818c21c80009480172c26f39944202fc83', -// miner: '0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8', -// mixHash: '0xfde990a5350c56b44f0538a0b28d6d26d87f59934477ef73908b9d96c91d6e59', -// nonce: '0xea5a783eb0e0e46b', -// number: 14965990, -// parentHash: '0xef7f2e8cb41f37c021b236bc3ea9d2c4e6b0fceefdb3c2c646384b7b2fe116a5', -// receiptsRoot: '0x327f816a10ba5bcc702055d419baa731346131cc2dda49e64b7ba9e5a7fd49bb', -// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -// size: 541, -// stateRoot: '0x4276888e92368eac990a4bbcda938c9c29bd94f85b134b218990d1b137dc234d', -// timestamp: 1655273068, -// transactionsRoot: '0x1717925d728173ce122b91199383468dbce68bda5e308d2a16f00725bab7b140', -// uncles: [] -// } +##### `web3.eth.getTransaction` -// in 4.x -await web3.eth.getUncle(14965991, 0); -// { -// baseFeePerGas: '0x8483af679', -// difficulty: '0x31776cc9a24e7f', -// extraData: '0x617369612d65617374322d3132', -// gasLimit: '0x1cb1a95', -// gasUsed: '0xaf47f1', -// hash: '0xf049e44dba7ae7c45239de3e2264ead7abd86fec3399ae2234edf778e936885c', -// logsBloom: '0x206cab47e94018b154281022c05863330003318c70a0ca4460244b4134a88517302d93c854b8068110a11b1342212335ba2020000d12fc330a44489e013e20149006f2034180105e7a820219b52861a241a210ca8d50385d3c481c21a8406c509a584cb15a226e0620111a884c262b9236010cf444700c030e2480f7200a6484b22b15a012c29903b40c0cc4830304c665003cc1b1b240b8752087d8ea1261e2ef8e293711c26d3b2b87c0988dd928d2d1a427340a90900641270ea6008a4d10032424ef0c0209789b424b4c304f5a0700640a40dfae02506303396e85182021203170182904980140409004cde41f818c21c80009480172c26f39944202fc83', -// miner: '0xea674fdde714fd979de3edf0f56aa9716b898ec8', -// mixHash: '0xfde990a5350c56b44f0538a0b28d6d26d87f59934477ef73908b9d96c91d6e59', -// nonce: '0xea5a783eb0e0e46b', -// number: '0xe45ce6', -// parentHash: '0xef7f2e8cb41f37c021b236bc3ea9d2c4e6b0fceefdb3c2c646384b7b2fe116a5', -// receiptsRoot: '0x327f816a10ba5bcc702055d419baa731346131cc2dda49e64b7ba9e5a7fd49bb', -// sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -// size: '0x21d', -// stateRoot: '0x4276888e92368eac990a4bbcda938c9c29bd94f85b134b218990d1b137dc234d', -// timestamp: '0x62a9766c', -// transactionsRoot: '0x1717925d728173ce122b91199383468dbce68bda5e308d2a16f00725bab7b140', -// uncles: [] -// } -``` - -### `web3.eth.getTransaction` - -- Returns a bigint instead of a number for the following properties: +- Returns a `BigInt` instead of a number for the following properties: - `blockNumber` - `gas` - `nonce` - `transactionIndex` - `type` -- Returns a bigint instead of a number string for the following properties: +- Returns a `BigInt` instead of a number string for the following properties: - `gasPrice` - `maxFeePerGas` - `maxPriorityFeePerGas` - `value` - `chainId` -```typescript -// in 1.x -await web3.eth.getTransaction('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); -// { -// accessList: [], -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: 14966017, -// chainId: '0x1', -// from: '0x3b7414bE92e87837D6f95D01B8E3c93aC9D20804', -// gas: 21000, -// gasPrice: '31200410061', -// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// input: '0x', -// maxFeePerGas: '56156626189', -// maxPriorityFeePerGas: '1500000000', -// nonce: 272, -// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', -// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', -// to: '0x8b664E252B7c5C87c17e73C69F16E56454C9661F', -// transactionIndex: 80, -// type: 2, -// v: '0x1', -// value: '13066966539051000' -// } +##### `web3.eth.getPendingTransactions` -// in 4.x -await web3.eth.getTransaction('0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593'); -// { -// accessList: [], -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: 14966017n, -// chainId: 1n, -// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', -// gas: 21000n, -// gasPrice: 31200410061n, -// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// input: '0x', -// maxFeePerGas: 56156626189n, -// maxPriorityFeePerGas: 1500000000n, -// nonce: 272n, -// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', -// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', -// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', -// transactionIndex: 80n, -// type: 2n, -// v: 1n, -// value: 13066966539051000n -// } -``` - -### `web3.eth.getPendingTransactions` - -- Returns a bigint instead of a number for the following properties: +- Returns a `BigInt` instead of a number for the following properties: - `blockNumber` - `gas` - `nonce` - `transactionIndex` - `type` -- Returns a bigint instead of a number string for the following properties: +- Returns a `BigInt` instead of a number string for the following properties: - `gasPrice` - `maxFeePerGas` - `maxPriorityFeePerGas` - `value` -```typescript -// in 1.x -await web3.eth.getPendingTransactions(); -// [ -// { -// accessList: [], -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: 14966017n, -// chainId: 1n, -// from: '0x3b7414bE92e87837D6f95D01B8E3c93aC9D20804', -// gas: 21000n, -// gasPrice: '31200410061n', -// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// input: '0x', -// maxFeePerGas: 56156626189n, -// maxPriorityFeePerGas: 1500000000n, -// nonce: 272n, -// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', -// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', -// to: '0x8b664E252B7c5C87c17e73C69F16E56454C9661F', -// transactionIndex: 80n, -// type: 2n, -// v: '0x1', -// value: 13066966539051000n -// }, -// ...] - -// in 4.x -await web3.eth.getPendingTransactions(); -// [ -// { -// accessList: [], -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: '0xe45d01', -// chainId: '0x1', -// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', -// gas: '0x5208', -// gasPrice: '0x743b079cd', -// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// input: '0x', -// maxFeePerGas: '0xd13321d0d', -// maxPriorityFeePerGas: '0x59682f00', -// nonce: '0x110', -// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', -// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', -// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', -// transactionIndex: '0x50', -// type: '0x2', -// v: '0x1', -// value: '0x2e6c563ada1ff8' -// }, -// ...] -``` - -### `web3.eth.getTransactionFromBlock` +##### `web3.eth.getTransactionFromBlock` -- Returns a bigint instead of a number for the following properties: +- Returns a `BigInt` instead of a number for the following properties: - `blockNumber` - `gas` - `nonce` - `transactionIndex` - `type` -- Returns a bigint instead of a number string for the following properties: +- Returns a `BigInt` instead of a number string for the following properties: - `gasPrice` - `maxFeePerGas` - `maxPriorityFeePerGas` - `value` -```typescript -// in 1.x -await web3.eth.getTransactionFromBlock('latest', 1); -// { -// accessList: [], -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: 14966017, -// chainId: '0x1', -// from: '0x3b7414bE92e87837D6f95D01B8E3c93aC9D20804', -// gas: 21000, -// gasPrice: '31200410061', -// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// input: '0x', -// maxFeePerGas: '56156626189', -// maxPriorityFeePerGas: '1500000000', -// nonce: 272, -// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', -// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', -// to: '0x8b664E252B7c5C87c17e73C69F16E56454C9661F', -// transactionIndex: 80, -// type: 2, -// v: '0x1', -// value: '13066966539051000' -// } +##### `web3.eth.getTransactionReceipt` -// in 4.x -await web3.eth.getTransactionFromBlock('latest', 1); -// { -// accessList: [], -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: 0xe45d01n, -// chainId: 1n, -// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', -// gas: 5208n, -// gasPrice: 0x743b079cdn, -// hash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// input: '0x', -// maxFeePerGas: d13321d0dn, -// maxPriorityFeePerGas: 59682f00n, -// nonce: 110n, -// r: '0xca990b477b7043937d2ead588981464399101c02c0b0c6323acee28427a12f39', -// s: '0x7c1d2571f7c2fe8bdf74cdecdb719a29e0b76b379c1bae8baf0164ddf7d6b3b8', -// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', -// transactionIndex: 50n, -// type: 2n, -// v: '0x1', -// value: 2e6c563ada1ff8n -// } -``` +- Returns a `BigInt` instead of a number for the following properties: + - `blockNumber` + - `cumulativeGasUsed` + - `effectiveGasPrice` + - `gasUsed` + - `transactionIndex` +- Returns a `BigInt` instead of a boolean for the following properties: + - `status` -### `web3.eth.getTransactionReceipt` +##### `web3.eth.sendSignedTransaction` -- Returns a bigint instead of a number for the following properties: +- Returns a `BigInt` instead of a number for the following properties: - `blockNumber` - `cumulativeGasUsed` - `effectiveGasPrice` - `gasUsed` - `transactionIndex` -- Returns a bigint instead of a boolean for the following properties: +- Returns a `BigInt` instead of a boolean for the following properties: - `status` -```typescript -// in 1.x -await web3.eth.getTransactionReceipt( - '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -); -// { -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: 14966017, -// contractAddress: null, -// cumulativeGasUsed: 6992382, -// effectiveGasPrice: 31200410061, -// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', -// gasUsed: 21000, -// logs: [], -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// status: true, -// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', -// transactionHash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// transactionIndex: 80, -// type: '0x2' -// } +### Not Implemented -// in 4.x -await web3.eth.getTransactionReceipt( - '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -); -// { -// blockHash: '0x55ff0699736027fd0eddf90e890294ba6765ecf699cefd2f6c255a2fdae06a5a', -// blockNumber: 14966017n, -// cumulativeGasUsed: 6992382n, -// effectiveGasPrice: 31200410061n, -// from: '0x3b7414be92e87837d6f95d01b8e3c93ac9d20804', -// gasUsed: 21000n, -// logs: [], -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// status: 1n, -// to: '0x8b664e252b7c5c87c17e73c69f16e56454c9661f', -// transactionHash: '0x219f94fa188e6a0927c3c659537b5c76f4a750b948e7a73c80b28786227aa593', -// transactionIndex: 80n, -// type: 2n -// } -``` +- [extend](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#extend) functionality not implemented -### `web3.eth.getTransactionCount` +### Defaults and Configs -returns a bigint instead of a number +- All default values that returned `null` in 1.x, in 4.x return `undefined`. There are: + + - `givenProvider` + - `currentProvider` + - `web3.eth.defaultAccount` + - 1.x has `undefined` documented as default, but in implementation it's `null` + +- `web3.eth.defaultHardfork` default is `london` instead of `undefined` + - 1.x has `london` documented as default, but in implementation it's `undefined` +- `web3.eth.defaultChain` default is `mainnet` instead of `undefined` + - 1.x has `mainnet` documented as default, but in implementation it's `undefined` + +### Web3Eth Methods + +### `web3.eth.getHashrate` + +`getHashrate` is deprecated, and will be removed in a future release. Please use `getHashRate` + +### `web3.eth.getFeeHistory` + +`4.x` returns a `BigInt` for `oldestBlock` instead of the hex string that's returned in `1.x` ```typescript // in 1.x -await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); // 0 +await web3.eth.getFeeHistory('0x1', 'latest', []); +// { +// oldestBlock: '0x0', +// baseFeePerGas: [ '0x3b9aca00', '0x342770c0' ], +// gasUsedRatio: [ 0 ] +// } // in 4.x -await web3.eth.getTransactionCount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); // 0n +await web3.eth.getFeeHistory('0x1', 'latest', []); +// { +// oldestBlock: 0n, +// baseFeePerGas: [ '0x3b9aca00', '0x342770c0' ], +// gasUsedRatio: [ 0 ] +// } ``` ### `web3.eth.sendTransaction` @@ -586,13 +235,13 @@ web3.eth.sendTransaction({ ... }).on('sent', (sentTransactionObject) => { ... }) ##### `receipt` - The `receipt` object the event listener receives: - - Returns a bigint instead of a number for the following properties: + - Returns a `BigInt` instead of a number for the following properties: - `transactionIndex` - `blockNumber` - `cumulativeGasUsed` - `gasUsed` - `effectiveGasPrice` - - Returns a bigint instead of a boolean for the following properties: + - Returns a `BigInt` instead of a boolean for the following properties: - `status` ```typescript @@ -638,15 +287,15 @@ web3.eth.sendTransaction({ ... }).on('receipt', (receipt) => { ... }); ##### `confirmation` - In `1.x`, this event listener would receive `confirmationNumber` and `receipt` as arguments, in `4.x` an object containing the properties: `confirmationNumber`, `receipt`, and `latestBlockHash` will be received -- `confirmationNumber` is returned as a bigint instead of a number +- `confirmationNumber` is returned as a `BigInt` instead of a number - For the returned `receipt` object: - - Returns a bigint instead of a number for the following properties: + - Returns a `BigInt` instead of a number for the following properties: - `transactionIndex` - `blockNumber` - `cumulativeGasUsed` - `gasUsed` - `effectiveGasPrice` - - Returns a bigint instead of a boolean for the following properties: + - Returns a `BigInt` instead of a boolean for the following properties: - `status` ```typescript @@ -700,210 +349,170 @@ web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationObject) => { . ```typescript // in 1.x web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationNumber, receipt) => { - // confirmationNumber would eqaul 1 the first time the event was emitted - // confirmationNumber would then eqaul 2 the next time + // confirmationNumber would equal 1 the first time the event was emitted + // confirmationNumber would then equal 2 the next time // and so on until 12 (or whatever transactionConfirmationBlocks is set to) confirmations are found }); // in 4.x web3.eth.sendTransaction({ ... }).on('confirmation', (confirmationObject) => { - // confirmationNumber would eqaul 2 the first time the event was emitted - // confirmationNumber would then eqaul 3 the next time + // confirmationNumber would equal 2 the first time the event was emitted + // confirmationNumber would then equal 3 the next time // and so on until 12 (or whatever transactionConfirmationBlocks is set to) confirmations are found }); ``` -### `web3.eth.sendSignedTransaction` - -- Returns a bigint instead of a number for the following properties: - - `blockNumber` - - `cumulativeGasUsed` - - `effectiveGasPrice` - - `gasUsed` - - `transactionIndex` -- Returns a bigint instead of a boolean for the following properties: - - `status` - -```ts -//in 1.x -web3.eth.sendSignedTransaction({...}).then(console.log); -// { -// blockHash: '0xd2964dacbc71217cb8d58b1f3f7ac03d4abbbbd500e13bd505bbdac8361f6fae', -// blockNumber: 9, -// contractAddress: null, -// cumulativeGasUsed: 21000, -// effectiveGasPrice: 20000000000, -// from: '0xd8c375f286c258521564da00ddee3945d1d057c4', -// gasUsed: 21000, -// logs: [], -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// status: true, -// to: '0x3535353535353535353535353535353535353535', -// transactionHash: '0x2bd1f369a1f9fba4b12a597761f771c34031f67584ed3c5e28a4c915ef0a1f83', -// transactionIndex: 0, -// type: '0x0' -// } - -//in 4.x -web34.eth.sendSignedTransaction({...}).then(console.log); -// { -// blockHash: '0xf433c7285366ae50334048ea2a290acc46db49abe75c5166bf71fe410834f338', -// blockNumber: 10n, -// cumulativeGasUsed: 21000n, -// effectiveGasPrice: 20000000000n, -// from: '0xd8c375f286c258521564da00ddee3945d1d057c4', -// gasUsed: 21000n, -// logs: [], -// logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', -// status: 1n, -// to: '0x3535353535353535353535353535353535353535', -// transactionHash: '0x739c5a6593e20bd545c264482a6bb9e7aebc504559e6406a4ed2fde4bf9dad72', -// transactionIndex: 0n, -// type: '0x0' -// } -``` - ### `web3.eth.sign` -The message must be converted to hex first. +- To-be-signed data must be provided as a Hex String -```ts -//in 1.x both work -web3.eth.sign('Hello world', '0xd8c375f286c258521564da00ddee3945d1d057c4').then(console.log); -//0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c -web3.eth - .sign(web3.utils.utf8ToHex('Hello world'), '0xd8c375f286c258521564da00ddee3945d1d057c4') - .then(console.log); -//0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c +```typescript +// In 1.x, data can be provided as both a UTF-8 string and a hex string +await web3.eth.sign('Hello world', '0xd8c375f286c258521564da00ddee3945d1d057c4'); +// 0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c +await web3.eth.sign( + web3.utils.utf8ToHex('Hello world'), + '0xd8c375f286c258521564da00ddee3945d1d057c4', +); +// 0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c -//in 4.x message must converted beforehand -web3.eth - .sign(web3.utils.utf8ToHex('Hello world'), '0xd8c375f286c258521564da00ddee3945d1d057c4') - .then(console.log); -//0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c +// 4.x only supports Hex Strings +await web3.eth.sign( + web3.utils.utf8ToHex('Hello world'), + '0xd8c375f286c258521564da00ddee3945d1d057c4', +); +// 0x7907ca312eb55a54673255dfa4e947d7533dcf746460c82b50e281fe88a6f0d17d602d2205b2d7c137cf7cb9b86a7ea976fd062e39bc08373dffa72f020776e11c ``` ### `web3.eth.signTransaction` -- In 1.x documentation examples, the nonce seems to be optional since it isn't present in the payload, but, it is required. It is required in 4.x, too. In 1.x nonce should be a number, in 4.x it can be number or string or hex string. - -- 1.x sets gasPrice (or maxPriorityFeePerGas & maxFeePerGas) to null in EIP-1559 transactions (in not EIP-1559 transactions) in the tx object. In 4.x instead of null, they are not present. +- In `1.x`, for untyped, `0x0` and `0x1` typed transactions, `maxPriorityFeePerGas` and `maxFeePerGas` are set to `null`. For `0x2` typed transactions, `gasPrice` is set to `null`. In `4.x` these properties are not present unless provided +- In `1.x` contract deployment data is provided via the `input` property, while in `4.x` it is provided using the `data` property +- In `1.x` the hash of the transaction is included in the returned transaction object, while in `4.x` it's not -- In 1.x the hash of the tx is present, in 4.x not. - -```ts -//in 1.x -let payload = { - from: '0xd8c375f286c258521564da00ddee3945d1d057c4', - nonce: web3.utils.hexToNumber( - await web3.eth.getTransactionCount('0xd8c375f286c258521564da00ddee3945d1d057c4'), - ), - gasPrice: '20000000000', +```typescript +// In 1.x - Legacy (type 0x0) transaction +await web3.eth.signTransaction({ + from: '0x95Cd1391888fe2460371c67cc3e45b9579c3E0dA', + to: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4', gas: '21000', - to: '0x3535353535353535353535353535353535353535', - value: '1000000000000000000', - data: '', -}; - -web3.eth.signTransaction(payload).then(console.log); + gasPrice: '0xc3e17d20', + nonce: '0x4', +}); // { -// raw: '0xf86e808504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080820a96a0a6dec055b314bd54c4ac294d6f298dbf8e0e4b1581d1bb916ad728ae26b55d80a01eb7b15974101a58acc6d6a976a32f058b6bdbdb2c3c4b9062865264613ef92f', -// tx: { -// type: '0x0', -// nonce: '0x0', -// gasPrice: '0x4a817c800', -// maxPriorityFeePerGas: null, -// maxFeePerGas: null, -// gas: '0x5208', -// value: '0xde0b6b3a7640000', -// input: '0x', -// v: '0xa96', -// r: '0xa6dec055b314bd54c4ac294d6f298dbf8e0e4b1581d1bb916ad728ae26b55d80', -// s: '0x1eb7b15974101a58acc6d6a976a32f058b6bdbdb2c3c4b9062865264613ef92f', -// to: '0x3535353535353535353535353535353535353535', -// hash: '0xfa45fc0923d6290ea1d0e597d81ed90d4594d82ef746eafcc36d2e4474e38fd0' -// } +// raw: '0x02f86c82053904849502f90084c3e17d20825208946e599da0bff7a6598ac1224e4985430bf16458a48080c080a0711c981b34204725019d9851ee0c127543b0c7caf4f8850024e26aefabf26f20a033d8447d959bd596c90d57db90917a126b95a0f152c9c86b36d97b177f7ae85f', +// tx: { +// type: '0x2', +// nonce: '0x4', +// gasPrice: '0xc3e17d20, +// maxPriorityFeePerGas: null, +// maxFeePerGas: null, +// gas: '0x5208', +// value: '0x0', +// input: '0x', +// v: '0x0', +// r: '0x711c981b34204725019d9851ee0c127543b0c7caf4f8850024e26aefabf26f20', +// s: '0x33d8447d959bd596c90d57db90917a126b95a0f152c9c86b36d97b177f7ae85f', +// to: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// chainId: '0x539', +// accessList: [], +// hash: '0x2ddb1224899bcbc07c89631870870c61195214bab64d60985cd6d8f1c2fd872b' +// } // } -//in 4.x -let payload = { - from: '0xd8c375f286c258521564da00ddee3945d1d057c4', - nonce: await web3.eth.getTransactionCount('0xd8c375f286c258521564da00ddee3945d1d057c4'), - gasPrice: '20000000000', +// In 1.x - EIP-1559 (type 0x2) transaction +await web3.eth.signTransaction({ + from: '0x95Cd1391888fe2460371c67cc3e45b9579c3E0dA', + to: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4', gas: '21000', - to: '0x3535353535353535353535353535353535353535', - value: '1000000000000000000', - data: '', -}; - -web3.eth.signTransaction(payload).then(console.log); -// raw: '0xf86e808504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080820a96a0a6dec055b314bd54c4ac294d6f298dbf8e0e4b1581d1bb916ad728ae26b55d80a01eb7b15974101a58acc6d6a976a32f058b6bdbdb2c3c4b9062865264613ef92f', -// tx: { -// type: '0x0', -// nonce: '0x0', -// gasPrice: '0x4a817c800', -// gas: '0x5208', -// value: '0xde0b6b3a7640000', -// v: '0xa96', -// r: '0xa6dec055b314bd54c4ac294d6f298dbf8e0e4b1581d1bb916ad728ae26b55d80', -// s: '0x1eb7b15974101a58acc6d6a976a32f058b6bdbdb2c3c4b9062865264613ef92f', -// to: '0x3535353535353535353535353535353535353535', -// data: '0x' -// } + maxPriorityFeePerGas: '0x9502F900', + maxFeePerGas: '0xc3e17d20', + nonce: '0x4', +}); +// { +// raw: '0x02f86c82053904849502f90084c3e17d20825208946e599da0bff7a6598ac1224e4985430bf16458a48080c080a0711c981b34204725019d9851ee0c127543b0c7caf4f8850024e26aefabf26f20a033d8447d959bd596c90d57db90917a126b95a0f152c9c86b36d97b177f7ae85f', +// tx: { +// type: '0x2', +// nonce: '0x4', +// gasPrice: null, +// maxPriorityFeePerGas: '0x9502f900', +// maxFeePerGas: '0xc3e17d20', +// gas: '0x5208', +// value: '0x0', +// input: '0x', +// v: '0x0', +// r: '0x711c981b34204725019d9851ee0c127543b0c7caf4f8850024e26aefabf26f20', +// s: '0x33d8447d959bd596c90d57db90917a126b95a0f152c9c86b36d97b177f7ae85f', +// to: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// chainId: '0x539', +// accessList: [], +// hash: '0x2ddb1224899bcbc07c89631870870c61195214bab64d60985cd6d8f1c2fd872b' +// } // } -``` - -### `web3.eth.call` -same as in 1.x, returns the returned data of the call - -```ts -const transaction = { - to: '0x99277D0A90F4A214c42B5B5b2c85B5ba2B46c809', - data: '0xcfae3217', -}; - -//in 1.x -web3.eth.call(transaction).then(console.log); -// 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000017736f6c79656e7420677265656e2069732070656f706c65000000000000000000 - -//in 4.x -web3.eth.call(transaction).then(console.log); -// 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000017736f6c79656e7420677265656e2069732070656f706c65000000000000000000 -``` - -### `web3.eth.estimateGas` - -returns a bigint instead of a number - -```ts -//in 1.x -web3.eth - .estimateGas({ - to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', - data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003', - }) - .then(console.log); -//21204 +// In 4.x - Legacy (type 0x0) transaction +await web3.eth.signTransaction({ + from: '0x95Cd1391888fe2460371c67cc3e45b9579c3E0dA', + to: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4', + gas: '21000', + gasPrice: '0xc3e17d20', + nonce: '0x4', +}); +// { +// raw: '0x02f86c82053904849502f90084c3e17d20825208946e599da0bff7a6598ac1224e4985430bf16458a48080c080a0711c981b34204725019d9851ee0c127543b0c7caf4f8850024e26aefabf26f20a033d8447d959bd596c90d57db90917a126b95a0f152c9c86b36d97b177f7ae85f', +// tx: { +// type: 2n, +// nonce: 4n, +// gasPrice: 3286334752n, +// gas: 21000n, +// value: 0n, +// v: 0n, +// r: '0x711c981b34204725019d9851ee0c127543b0c7caf4f8850024e26aefabf26f20', +// s: '0x33d8447d959bd596c90d57db90917a126b95a0f152c9c86b36d97b177f7ae85f', +// to: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// chainId: 1337n, +// accessList: [], +// data: '0x' +// } +// } -//in 4.x -web3.eth - .estimateGas({ - to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', - data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003', - }) - .then(console.log); -//21204n +// In 4.x - EIP-1559 (type 0x2) transaction +await web3.eth.signTransaction({ + from: '0x95Cd1391888fe2460371c67cc3e45b9579c3E0dA', + to: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4', + gas: '21000', + maxPriorityFeePerGas: '0x9502F900', + maxFeePerGas: '0xc3e17d20', + nonce: '0x4', +}); +// { +// raw: '0x02f86c82053904849502f90084c3e17d20825208946e599da0bff7a6598ac1224e4985430bf16458a48080c080a0711c981b34204725019d9851ee0c127543b0c7caf4f8850024e26aefabf26f20a033d8447d959bd596c90d57db90917a126b95a0f152c9c86b36d97b177f7ae85f', +// tx: { +// type: 2n, +// nonce: 4n, +// maxPriorityFeePerGas: 2500000000n, +// maxFeePerGas: 3286334752n, +// gas: 21000n, +// value: 0n, +// v: 0n, +// r: '0x711c981b34204725019d9851ee0c127543b0c7caf4f8850024e26aefabf26f20', +// s: '0x33d8447d959bd596c90d57db90917a126b95a0f152c9c86b36d97b177f7ae85f', +// to: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', +// chainId: 1337n, +// accessList: [], +// data: '0x' +// } +// } ``` ### `web3.eth.getPastLogs` -- Returns a bigint instead of a number for the following properties: +- Returns a `BigInt` instead of a number for the following properties: - `logIndex` - `transactionIndex` - `blockNumber` -```ts +```typescript //in 1.x await web3.eth .getPastLogs({ @@ -959,7 +568,7 @@ await web3.eth same as in 1.x -```ts +```typescript web3.eth.getWork().then(console.log); // [ // '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', @@ -972,7 +581,7 @@ web3.eth.getWork().then(console.log); same as in 1.x -```ts +```typescript web3.eth .submitWork([ '0x0000000000000001', @@ -987,16 +596,16 @@ web3.eth same as 1.x, returns array of addressed (must be used with injected provider) -```ts +```typescript await web3.eth.requestAccounts(); //['0xb839Aa3ECdd24c0Fa2fa382Ca179b88a0b33804f'] ``` ### `web3.eth.getChainId` -Returns a bigint instead of a number string +Returns a `BigInt` instead of a number string -```ts +```typescript //in 1.x web3.eth.getChainId().then(console.log); //1337 @@ -1010,20 +619,20 @@ web3.eth.getChainId().then(console.log); same as in 1.x -```ts +```typescript web3.eth.getNodeInfo().then(console.log); // Geth/v1.10.18-unstable-b3af0a55/linux-arm64/go1.18.1 ``` ### `web3.eth.getProof` -- Returns a bigint instead of a number string for the following properties: +- Returns a `BigInt` instead of a number string for the following properties: - `balance` - `nonce` `balance` and `nonce` in 1.x were described as numbers -```ts +```typescript //in 1.x web3.eth .getProof( From 7868fc0b90cd8d2eb37fb643cd405c25782dd1a3 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 7 Jul 2022 11:54:36 +0300 Subject: [PATCH 12/18] fix decode function. migration guide. fix unit tests (#5210) * fix decode function. migration guide. fix unit tests * :label: Fix the contract types (#5213) * fix contract integration tests * add to changelog.md Co-authored-by: Nazar Hussain --- CHANGELOG.md | 2 +- docs/docs/guides/abi_migration_guide.md | 5 ++ packages/web3-eth-abi/src/api/logs_api.ts | 9 ++- .../web3-eth-abi/src/api/parameters_api.ts | 31 ++++++--- packages/web3-eth-abi/src/types.ts | 65 ++++++++++-------- packages/web3-eth-abi/test/fixtures/data.ts | 66 +++++++++++++++++++ .../test/unit/api/parameters_api.test.ts | 8 +-- packages/web3-eth-contract/src/contract.ts | 2 +- packages/web3-eth-contract/src/encoding.ts | 9 ++- .../test/integration/contract_methods.test.ts | 7 +- .../web3-eth/test/integration/rpc.test.ts | 4 +- 11 files changed, 154 insertions(+), 54 deletions(-) create mode 100644 docs/docs/guides/abi_migration_guide.md diff --git a/CHANGELOG.md b/CHANGELOG.md index ca856c4d88f..f6c7de074fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -377,7 +377,7 @@ Released with 1.0.0-beta.37 code base. #### web3-eth-abi -1. `decodeParameters` decoding result is now the same format as the input parameter for encoding +1. `internalType` was renamed to `baseType` in all abi types #### web3-eth diff --git a/docs/docs/guides/abi_migration_guide.md b/docs/docs/guides/abi_migration_guide.md new file mode 100644 index 00000000000..b9c24fe46ef --- /dev/null +++ b/docs/docs/guides/abi_migration_guide.md @@ -0,0 +1,5 @@ +# Web3 Abi Migration Guide + +## Breaking Changes + +`internalType` was renamed to `baseType` in all abi types diff --git a/packages/web3-eth-abi/src/api/logs_api.ts b/packages/web3-eth-abi/src/api/logs_api.ts index 8b2ede0f008..92e6bfbffff 100644 --- a/packages/web3-eth-abi/src/api/logs_api.ts +++ b/packages/web3-eth-abi/src/api/logs_api.ts @@ -46,21 +46,20 @@ export const decodeLog = >( } } - const decodedNonIndexedInputs = data + const decodedNonIndexedInputs: { [key: string]: unknown; __length__: number } = data ? decodeParametersWith(Object.values(nonIndexedInputs), data, true) - : []; + : { __length__: 0 }; // If topics are more than indexed inputs, that means first topic is the event signature const offset = clonedTopics.length - Object.keys(indexedInputs).length; const decodedIndexedInputs = Object.values(indexedInputs).map((input, index) => STATIC_TYPES.some(s => input.type.startsWith(s)) - ? (decodeParameter(input.type, clonedTopics[index + offset])[0] as unknown[]) + ? decodeParameter(input.type, clonedTopics[index + offset]) : clonedTopics[index + offset], ); const returnValues: { [key: string]: unknown; __length__: number } = { __length__: 0 }; - returnValues.__length__ = 0; let indexedCounter = 0; let nonIndexedCounter = 0; @@ -74,7 +73,7 @@ export const decodeLog = >( } if (nonIndexedInputs[i]) { - returnValues[i] = decodedNonIndexedInputs[nonIndexedCounter]; + returnValues[i] = decodedNonIndexedInputs[String(nonIndexedCounter)]; nonIndexedCounter += 1; } diff --git a/packages/web3-eth-abi/src/api/parameters_api.ts b/packages/web3-eth-abi/src/api/parameters_api.ts index 70dfa828b59..8fd701f2b63 100644 --- a/packages/web3-eth-abi/src/api/parameters_api.ts +++ b/packages/web3-eth-abi/src/api/parameters_api.ts @@ -29,17 +29,21 @@ const formatDecodedObject = ( abi: { [key: string]: unknown }, input: { [key: string]: unknown }, ): { [key: string]: unknown } => { + let index = 0; const res: { [key: string]: unknown } = {}; for (const j of Object.keys(abi)) { if (typeof abi[j] === 'string') { res[j] = input[j]; + res[index] = input[j]; } if (typeof abi[j] === 'object') { res[j] = formatDecodedObject( abi[j] as { [key: string]: unknown }, input[j] as { [key: string]: unknown }, ); + res[index] = res[j]; } + index += 1; } return res; @@ -106,7 +110,7 @@ export const decodeParametersWith = ( abis: AbiInput[], bytes: HexString, loose: boolean, -): unknown[] => { +): { [key: string]: unknown; __length__: number } => { try { if (abis.length > 0 && (!bytes || bytes === '0x' || bytes === '0X')) { throw new AbiError( @@ -117,13 +121,14 @@ export const decodeParametersWith = ( 'or querying a node which is not fully synced.', ); } - const res = ethersAbiCoder.decode( mapTypes(abis).map(p => ParamType.from(p)), `0x${bytes.replace(/0x/i, '')}`, loose, ); - const returnList: unknown[] = []; + const returnValue: { [key: string]: unknown; __length__: number } = { + __length__: 0, + }; for (const [i, abi] of abis.entries()) { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment let decodedValue = res[i]; @@ -138,7 +143,7 @@ export const decodeParametersWith = ( // eslint-disable-next-line no-null/no-null decodedValue === '0x' && !isStringObject && !isStringType ? null : decodedValue; - if (!!abi && typeof abi === 'object' && !abi.name && !Array.isArray(abi)) { + if (!!abi && typeof abi === 'object' && !Array.isArray(abi)) { // the length of the abi object will always be 1 for (const j of Object.keys(abi)) { const abiObject: { [key: string]: unknown } = abi; // abi is readonly have to create a new const @@ -151,9 +156,14 @@ export const decodeParametersWith = ( } } } - returnList.push(decodedValue); + if (!!abi && typeof abi === 'object' && abi?.name) { + returnValue[(abi as { name: string })?.name] = decodedValue; + } + returnValue[i] = decodedValue; + returnValue.__length__ += 1; } - return returnList; + + return returnValue; } catch (err) { throw new AbiError(`Parameter decoding error: ${(err as Error).message}`); } @@ -165,8 +175,10 @@ export const decodeParametersWith = ( * @param abi * @param bytes */ -export const decodeParameters = (abi: AbiInput[], bytes: HexString) => - decodeParametersWith(abi, bytes, false); +export const decodeParameters = ( + abi: AbiInput[], + bytes: HexString, +): { [key: string]: unknown; __length__: number } => decodeParametersWith(abi, bytes, false); /** * Should be used to decode bytes to plain param @@ -174,4 +186,5 @@ export const decodeParameters = (abi: AbiInput[], bytes: HexString) => * @param abi * @param bytes */ -export const decodeParameter = (abi: AbiInput, bytes: HexString) => decodeParameters([abi], bytes); +export const decodeParameter = (abi: AbiInput, bytes: HexString): unknown => + decodeParameters([abi], bytes)['0']; diff --git a/packages/web3-eth-abi/src/types.ts b/packages/web3-eth-abi/src/types.ts index be453b3d03c..2b6c5141127 100644 --- a/packages/web3-eth-abi/src/types.ts +++ b/packages/web3-eth-abi/src/types.ts @@ -53,27 +53,27 @@ export type AbiBaseFragment = { export type AbiConstructorFragment = AbiBaseFragment & { readonly type: string | 'constructor'; readonly stateMutability: string | 'nonpayable' | 'payable'; - readonly inputs: ReadonlyArray; + readonly inputs?: ReadonlyArray; }; // https://docs.soliditylang.org/en/latest/abi-spec.html#json export type AbiFunctionFragment = AbiBaseFragment & { readonly name: string; readonly type: string | 'function'; - readonly stateMutability: string | 'nonpayable' | 'payable' | 'pure' | 'view'; - readonly inputs: ReadonlyArray; - readonly outputs: ReadonlyArray; + readonly stateMutability?: string | 'nonpayable' | 'payable' | 'pure' | 'view'; + readonly inputs?: ReadonlyArray; + readonly outputs?: ReadonlyArray; readonly constant?: boolean; // stateMutability == 'pure' or stateMutability == 'view' readonly payable?: boolean; // stateMutability == 'payable' }; export type AbiFallbackFragment = AbiBaseFragment & { - readonly name?: never; + readonly name: never; readonly type: string | 'fallback'; readonly stateMutability: string | 'nonpayable' | 'payable' | 'pure' | 'view'; - readonly inputs?: never; - readonly outputs?: never; + readonly inputs: never; + readonly outputs: never; // legacy properties readonly constant?: boolean; // stateMutability == 'pure' or stateMutability == 'view' @@ -84,7 +84,7 @@ export type AbiFallbackFragment = AbiBaseFragment & { export type AbiEventFragment = AbiBaseFragment & { readonly name: string; readonly type: string | 'event'; - readonly inputs: ReadonlyArray; + readonly inputs?: ReadonlyArray; readonly anonymous?: boolean; }; @@ -177,35 +177,42 @@ export type MatchPrimitiveType< | PrimitiveTupleType | never; -export type ContractMethodOutputParameters> = Params extends [] - ? [] - : Params extends [infer H, ...infer R] - ? H extends AbiParameter - ? // TODO: Find a way to set name for tuple item - [MatchPrimitiveType, ...ContractMethodOutputParameters] - : ContractMethodOutputParameters - : Params; - -export type ContractMethodInputParameters> = Params extends [] - ? [] - : Params extends [infer H, ...infer R] - ? H extends AbiParameter - ? // TODO: Find a way to set name for tuple item - [MatchPrimitiveType, ...ContractMethodInputParameters] - : ContractMethodInputParameters - : Params; +export type ContractMethodOutputParameters | undefined> = + Params extends readonly [] + ? [] + : Params extends readonly [infer H, ...infer R] + ? H extends AbiParameter + ? // TODO: Find a way to set name for tuple item + [MatchPrimitiveType, ...ContractMethodOutputParameters] + : ContractMethodOutputParameters + : Params extends undefined | unknown + ? [] + : Params; + +export type ContractMethodInputParameters | undefined> = + Params extends readonly [] + ? [] + : Params extends readonly [infer H, ...infer R] + ? H extends AbiParameter + ? // TODO: Find a way to set name for tuple item + [MatchPrimitiveType, ...ContractMethodInputParameters] + : ContractMethodInputParameters + : Params extends undefined | unknown + ? [] + : Params; export type ContractConstructor = { [Abi in FilterAbis as 'constructor']: { readonly Abi: Abi; - readonly Inputs: ContractMethodInputParameters<[...Abi['inputs']]>; + readonly Inputs: ContractMethodInputParameters; }; }['constructor']; export type ContractMethod = { readonly Abi: Abi; - readonly Inputs: ContractMethodInputParameters<[...Abi['inputs']]>; - readonly Outputs: ContractMethodOutputParameters<[...Abi['outputs']]>; + + readonly Inputs: ContractMethodInputParameters; + readonly Outputs: ContractMethodOutputParameters; }; export type ContractMethods = { @@ -217,7 +224,7 @@ export type ContractMethods = { export type ContractEvent = { readonly Abi: Abi; - readonly Inputs: ContractMethodInputParameters<[...Abi['inputs']]>; + readonly Inputs: ContractMethodInputParameters; }; export type ContractEvents = { diff --git a/packages/web3-eth-abi/test/fixtures/data.ts b/packages/web3-eth-abi/test/fixtures/data.ts index ee92d84b987..e25f171adf7 100644 --- a/packages/web3-eth-abi/test/fixtures/data.ts +++ b/packages/web3-eth-abi/test/fixtures/data.ts @@ -395,6 +395,7 @@ export const validDecodeLogsData: { export const validEncodeDecodeParametersData: { input: Parameters; output: ReturnType; + outputResult: any; }[] = [ { input: [ @@ -402,6 +403,11 @@ export const validEncodeDecodeParametersData: { ['2345675643', 'Hello!%'], ], output: '0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000', + outputResult: { + '0': '2345675643', + '1': 'Hello!%', + __length__: 2, + }, }, { input: [ @@ -409,6 +415,11 @@ export const validEncodeDecodeParametersData: { [['34', '255'], '0x324567fff0000000000000000000000000000000000000000000000000000000'], ], output: '0x0000000000000000000000000000000000000000000000000000000000000040324567fff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000ff', + outputResult: { + '0': ['34', '255'], + '1': '0x324567fff0000000000000000000000000000000000000000000000000000000', + __length__: 2, + }, }, { input: [ @@ -438,6 +449,28 @@ export const validEncodeDecodeParametersData: { ], ], output: '0x00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000ff', + outputResult: { + '0': ['34', '255'], + '1': { + '0': '42', + '1': '56', + '2': { + '0': '45', + '1': '78', + propertyOne: '45', + propertyTwo: '78', + }, + propertyOne: '42', + propertyTwo: '56', + ChildStruct: { + '0': '45', + '1': '78', + propertyOne: '45', + propertyTwo: '78', + }, + }, + __length__: 2, + }, }, ]; @@ -572,6 +605,7 @@ export const inValidEncodeParametersData: { export const validDecodeParametersData: { input: Parameters; output: unknown[]; + outputResult: any; }[] = [ { input: [ @@ -579,6 +613,11 @@ export const validDecodeParametersData: { '0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000', ], output: ['2345675643', 'Hello!%'], + outputResult: { + '0': '2345675643', + '1': 'Hello!%', + __length__: 2, + }, }, { input: [ @@ -589,6 +628,11 @@ export const validDecodeParametersData: { ['34', '255'], '0x324567fff0000000000000000000000000000000000000000000000000000000', ], + outputResult: { + '0': ['34', '255'], + '1': '0x324567fff0000000000000000000000000000000000000000000000000000000', + __length__: 2, + }, }, { input: [ @@ -618,6 +662,28 @@ export const validDecodeParametersData: { }, }, ], + outputResult: { + '0': ['34', '255'], + '1': { + '0': '42', + '1': '56', + '2': { + '0': '45', + '1': '78', + propertyOne: '45', + propertyTwo: '78', + }, + propertyOne: '42', + propertyTwo: '56', + ChildStruct: { + '0': '45', + '1': '78', + propertyOne: '45', + propertyTwo: '78', + }, + }, + __length__: 2, + }, }, ]; diff --git a/packages/web3-eth-abi/test/unit/api/parameters_api.test.ts b/packages/web3-eth-abi/test/unit/api/parameters_api.test.ts index 90849cea807..041c8a1d2c8 100644 --- a/packages/web3-eth-abi/test/unit/api/parameters_api.test.ts +++ b/packages/web3-eth-abi/test/unit/api/parameters_api.test.ts @@ -66,7 +66,7 @@ describe('parameters_api', () => { describe('valid data', () => { it.each(validDecodeParametersData)( '%#: should pass for valid values: %j', - ({ input: [abi, bytes], output }) => { + ({ input: [abi, bytes], outputResult }) => { // Output returns mix of array and object which can't be matched in // jest, so have to use stringify+parse to match // { @@ -82,7 +82,7 @@ describe('parameters_api', () => { // __length__: 2 // } expect(JSON.parse(JSON.stringify(decodeParameters(abi, bytes)))).toEqual( - output, + outputResult, ); }, ); @@ -102,12 +102,12 @@ describe('parameters_api', () => { describe('input should be the same as returned value from encode and decode', () => { it.each(validEncodeDecodeParametersData)( '%#: should pass for valid values: %j', - ({ input: [abi, params], output }) => { + ({ input: [abi, params], output, outputResult }) => { const rwAbi = abi as AbiInput[]; const encodedBytes = encodeParameters(abi, params); expect(encodedBytes).toEqual(output); const decodedBytes = decodeParameters(rwAbi, encodedBytes); - expect(decodedBytes).toEqual(params); + expect(decodedBytes).toEqual(outputResult); }, ); }); diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index cb9a82f80f3..61db8b6a0cc 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -893,7 +893,7 @@ export class Contract abi: T, ): ContractBoundMethod> { return (...params: unknown[]) => { - validator.validate(abi.inputs, params); + validator.validate(abi.inputs ?? [], params); if (abi.stateMutability === 'payable' || abi.stateMutability === 'pure') { return { diff --git a/packages/web3-eth-contract/src/encoding.ts b/packages/web3-eth-contract/src/encoding.ts index b233955e855..b4104337657 100644 --- a/packages/web3-eth-contract/src/encoding.ts +++ b/packages/web3-eth-contract/src/encoding.ts @@ -155,9 +155,10 @@ export const decodeEventABI = ( const argTopics = modifiedEvent.anonymous ? data.topics : (data.topics ?? []).slice(1); return { ...result, - returnValues: decodeLog([...modifiedEvent.inputs], data.data, argTopics), + returnValues: decodeLog([...(modifiedEvent.inputs ?? [])], data.data, argTopics), event: modifiedEvent.name, signature: modifiedEvent.anonymous || !data.topics[0] ? undefined : data.topics[0], + raw: { data: data.data, topics: data.topics, @@ -212,9 +213,13 @@ export const decodeMethodReturn = (abi: AbiFunctionFragment, returnValues?: HexS } const value = returnValues.length >= 2 ? returnValues.slice(2) : returnValues; + if (!abi.outputs) { + // eslint-disable-next-line no-null/no-null + return null; + } const result = decodeParameters([...abi.outputs], value); - if (result.length === 1) { + if (result.__length__ === 1) { return result[0]; } diff --git a/packages/web3-eth-contract/test/integration/contract_methods.test.ts b/packages/web3-eth-contract/test/integration/contract_methods.test.ts index dffd8c4ed09..80029587813 100644 --- a/packages/web3-eth-contract/test/integration/contract_methods.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_methods.test.ts @@ -46,7 +46,12 @@ describe('contract', () => { it('should retrieve the values', async () => { const result = await contract.methods.getValues().call(); - expect(result).toEqual(['10', 'string init value', false]); + expect(result).toEqual({ + '0': '10', + '1': 'string init value', + '2': false, + __length__: 3, + }); }); describe('revert handling', () => { diff --git a/packages/web3-eth/test/integration/rpc.test.ts b/packages/web3-eth/test/integration/rpc.test.ts index afe96172188..f7e314a5c5d 100644 --- a/packages/web3-eth/test/integration/rpc.test.ts +++ b/packages/web3-eth/test/integration/rpc.test.ts @@ -121,8 +121,8 @@ describe('rpc', () => { it('getAccounts', async () => { const account = await createNewAccount({ unlock: true }); - const accList = await web3Eth.getAccounts() - const accListLowerCase = accList.map((add: string)=>add.toLowerCase()); + const accList = await web3Eth.getAccounts(); + const accListLowerCase = accList.map((add: string) => add.toLowerCase()); expect(accListLowerCase).toContain(accounts[0].toLowerCase()); expect(accListLowerCase).toContain(accounts[1].toLowerCase()); expect(accListLowerCase).toContain(account.address.toLowerCase()); From bb5c7e651b44138f2ca43a4092d397e1694dd572 Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Thu, 7 Jul 2022 15:03:09 +0300 Subject: [PATCH 13/18] Incompatible return types for 4.x implementations (#5205) * Throw error for not found tx in getTransaction * Fix failing tests * Move mock values to fixtures * Throw error for not found tx in getTransactionReceipt * Create dedicated error * Create dedicated error code --- packages/web3-errors/src/error_codes.ts | 1 + .../src/errors/transaction_errors.ts | 7 ++++ packages/web3-eth/src/web3_eth.ts | 21 ++++++++++- .../web3_eth_methods_with_parameters.ts | 37 +++++++++++++++++++ .../web3_eth_methods_with_parameters.test.ts | 5 +++ 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/packages/web3-errors/src/error_codes.ts b/packages/web3-errors/src/error_codes.ts index ba90826a699..25ba73dcec7 100644 --- a/packages/web3-errors/src/error_codes.ts +++ b/packages/web3-errors/src/error_codes.ts @@ -73,6 +73,7 @@ export const ERR_TX_RECEIPT_MISSING_BLOCK_NUMBER = 428; export const ERR_TX_LOCAL_WALLET_NOT_AVAILABLE = 429; +export const ERR_TX_NOT_FOUND = 430; // Connection error codes export const ERR_CONN = 500; export const ERR_CONN_INVALID = 501; diff --git a/packages/web3-errors/src/errors/transaction_errors.ts b/packages/web3-errors/src/errors/transaction_errors.ts index f01a76ffcca..ca4d521d108 100644 --- a/packages/web3-errors/src/errors/transaction_errors.ts +++ b/packages/web3-errors/src/errors/transaction_errors.ts @@ -26,6 +26,7 @@ import { ERR_TX_REVERT_INSTRUCTION, ERR_TX_REVERT_TRANSACTION, ERR_TX_REVERT_WITHOUT_REASON, + ERR_TX_NOT_FOUND, } from '../error_codes'; import { ReceiptInfo } from '../types'; import { Web3Error } from '../web3_error_base'; @@ -125,3 +126,9 @@ export class UndefinedRawTransactionError extends TransactionError { this.code = ERR_RAW_TX_UNDEFINED; } } +export class TransactionNotFound extends TransactionError { + public constructor() { + super('Transaction not found'); + this.code = ERR_TX_NOT_FOUND; + } +} diff --git a/packages/web3-eth/src/web3_eth.ts b/packages/web3-eth/src/web3_eth.ts index 47042c47cf0..f7927682f8f 100644 --- a/packages/web3-eth/src/web3_eth.ts +++ b/packages/web3-eth/src/web3_eth.ts @@ -24,6 +24,7 @@ import { Web3Context, Web3ContextInitOptions, } from 'web3-core'; +import { TransactionNotFound } from 'web3-errors'; import { Address, Bytes, @@ -207,7 +208,15 @@ export class Web3Eth extends Web3Context(transactionHash: Bytes, returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat) { - return rpcMethodsWrappers.getTransactionReceipt(this, transactionHash, returnFormat); + const response = await rpcMethodsWrappers.getTransactionReceipt( + this, + transactionHash, + returnFormat, + ); + + if (!response) throw new TransactionNotFound(); + + return response; } public async getTransactionCount< diff --git a/packages/web3-eth/test/fixtures/web3_eth_methods_with_parameters.ts b/packages/web3-eth/test/fixtures/web3_eth_methods_with_parameters.ts index 37f24e1b290..c45a58461d0 100644 --- a/packages/web3-eth/test/fixtures/web3_eth_methods_with_parameters.ts +++ b/packages/web3-eth/test/fixtures/web3_eth_methods_with_parameters.ts @@ -28,6 +28,7 @@ import { Uint256, } from 'web3-utils'; import { transactionWithSender } from './rpc_methods_wrappers'; +import { ReceiptInfo } from '../../src/types'; /** * Array consists of: @@ -1835,3 +1836,39 @@ export const getProofValidData: [ ], ], ]; + +export const tx = { + blockHash: '0xb3a667f84f58c90ab87476073e06c5d1186a0f0b0b69aa3033bfe0e4df264350', + blockNumber: '123', + from: '0x01ada9d3470eb9eb3875d9e7948c674804ca43ae', + gas: '21000', + gasPrice: '10000', + hash: '0x84f44dffc3cd90a1b66ad0219a97680308e5e7a77299fbf1e2ebb572cf02cc2d', + input: '0x', + nonce: '61', + to: '0x0000000000000000000000000000000000000000', + transactionIndex: '0', + value: '1', + type: '0x01', + v: '2710', + r: '0xbefb00433ef79b2609dc560c28963c2e954370792671f71ab99665b8807b7feb', + s: '0x6bebe5e2c9f839d3ce0264dc5c7cc521f902e86705c69f5fddffaa3de5aac6d3', +}; + +export const txReceipt: ReceiptInfo = { + blockHash: '0xb3a667f84f58c90ab87476073e06c5d1186a0f0b0b69aa3033bfe0e4df264350', + blockNumber: BigInt(123), + cumulativeGasUsed: BigInt(21000), + effectiveGasPrice: BigInt(10000), + from: '0x01ada9d3470eb9eb3875d9e7948c674804ca43ae', + gasUsed: BigInt(21000), + logs: [], + logsBloom: + '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + status: BigInt(1), + to: '0x0000000000000000000000000000000000000000', + transactionHash: '0x84f44dffc3cd90a1b66ad0219a97680308e5e7a77299fbf1e2ebb572cf02cc2d', + transactionIndex: BigInt(0), + type: BigInt(0), + root: '', +}; diff --git a/packages/web3-eth/test/unit/web3_eth_methods_with_parameters.test.ts b/packages/web3-eth/test/unit/web3_eth_methods_with_parameters.test.ts index 2b5a321c950..2920e756c5e 100644 --- a/packages/web3-eth/test/unit/web3_eth_methods_with_parameters.test.ts +++ b/packages/web3-eth/test/unit/web3_eth_methods_with_parameters.test.ts @@ -49,10 +49,15 @@ import { sendSignedTransactionValidData, signValidData, submitWorkValidData, + tx, + txReceipt, } from '../fixtures/web3_eth_methods_with_parameters'; jest.mock('../../src/rpc_methods'); jest.mock('../../src/rpc_method_wrappers'); +// eslint-disable-next-line @typescript-eslint/no-unsafe-call +jest.spyOn(rpcMethodWrappers, 'getTransaction').mockResolvedValue(tx); +jest.spyOn(rpcMethodWrappers, 'getTransactionReceipt').mockResolvedValue(txReceipt); describe('web3_eth_methods_with_parameters', () => { let web3Eth: Web3Eth; From 4d75b65ad91d943cb8b35a2550f1744080243913 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 7 Jul 2022 18:02:18 +0200 Subject: [PATCH 14/18] Upgrade ethereum-cryptography to 1.0 (#5211) * :arrow_up: Update ethereum-cryptography package * Apply suggestions from code review Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> * :art: Update the code as per feedback Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> --- packages/web3-eth-accounts/package.json | 3 +- packages/web3-eth-accounts/src/account.ts | 185 +++++++++--------- .../test/fixtures/account.ts | 50 ++++- .../test/unit/account.test.ts | 73 ++++--- packages/web3-utils/package.json | 2 +- packages/web3-validator/package.json | 2 +- yarn.lock | 95 ++++----- 7 files changed, 231 insertions(+), 179 deletions(-) diff --git a/packages/web3-eth-accounts/package.json b/packages/web3-eth-accounts/package.json index e1e34e71a99..ec28624b803 100644 --- a/packages/web3-eth-accounts/package.json +++ b/packages/web3-eth-accounts/package.json @@ -42,8 +42,7 @@ "dependencies": { "web3-errors": "1.0.0-alpha.0", "@ethereumjs/tx": "^3.4.0", - "ethereum-cryptography": "^0.2.1", - "secp256k1": "^4.0.2", + "ethereum-cryptography": "^1.1.0", "web3-common": "^1.0.0-alpha.0", "web3-utils": "^4.0.0-alpha.1", "web3-validator": "^0.1.0-alpha.0" diff --git a/packages/web3-eth-accounts/src/account.ts b/packages/web3-eth-accounts/src/account.ts index d3dd7b31611..231c095b63b 100644 --- a/packages/web3-eth-accounts/src/account.ts +++ b/packages/web3-eth-accounts/src/account.ts @@ -15,55 +15,83 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ +import { TransactionFactory, TypedTransaction } from '@ethereumjs/tx'; +import { decrypt as createDecipheriv, encrypt as createCipheriv } from 'ethereum-cryptography/aes'; +import { pbkdf2Sync } from 'ethereum-cryptography/pbkdf2'; +import { scryptSync } from 'ethereum-cryptography/scrypt'; +import { getPublicKey, recoverPublicKey, signSync, utils } from 'ethereum-cryptography/secp256k1'; import { + InvalidKdfError, + InvalidPasswordError, InvalidPrivateKeyError, - PrivateKeyLengthError, - UndefinedRawTransactionError, - SignerError, InvalidSignatureError, - InvalidKdfError, + IVLengthError, KeyDerivationError, KeyStoreVersionError, - InvalidPasswordError, - IVLengthError, PBKDF2IterationsError, + PrivateKeyLengthError, + SignerError, + UndefinedRawTransactionError, } from 'web3-errors'; -import { utils, getPublicKey } from 'ethereum-cryptography/secp256k1'; -import { keccak256 } from 'ethereum-cryptography/keccak'; -import { TransactionFactory, TypedTransaction } from '@ethereumjs/tx'; -import { ecdsaSign, ecdsaRecover } from 'secp256k1'; -import { pbkdf2Sync } from 'ethereum-cryptography/pbkdf2'; -import { scryptSync } from 'ethereum-cryptography/scrypt'; -import { encrypt as createCipheriv, decrypt as createDecipheriv } from 'ethereum-cryptography/aes'; import { - toChecksumAddress, + Address, + Bytes, + bytesToBuffer, bytesToHex, - sha3Raw, HexString, - randomBytes, hexToBytes, - Address, isHexStrict, + numberToHex, + randomBytes, + sha3Raw, + toChecksumAddress, utf8ToHex, } from 'web3-utils'; -import { validator, isBuffer, isHexString32Bytes, isString, isNullish } from 'web3-validator'; +import { isBuffer, isNullish, isString, validator } from 'web3-validator'; +import { keyStoreSchema } from './schemas'; import { + CipherOptions, + KeyStore, + PBKDF2SHA256Params, + ScryptParams, SignatureObject, SignResult, SignTransactionResult, - KeyStore, - ScryptParams, - PBKDF2SHA256Params, - CipherOptions, Web3Account, } from './types'; -import { keyStoreSchema } from './schemas'; + +/** + * Get the private key buffer after the validation + * + * @param data - The data in any bytes format + * @returns + */ +export const parseAndValidatePrivateKey = (data: Bytes): Buffer => { + let privateKeyBuffer: Buffer; + + // To avoid the case of 1 character less in a hex string which is prefixed with '0' by using 'bytesToBuffer' + if (typeof data === 'string' && isHexStrict(data) && data.length !== 66) { + throw new PrivateKeyLengthError(); + } + + try { + privateKeyBuffer = Buffer.isBuffer(data) ? data : bytesToBuffer(data); + } catch { + throw new InvalidPrivateKeyError(); + } + + if (privateKeyBuffer.byteLength !== 32) { + throw new PrivateKeyLengthError(); + } + + return privateKeyBuffer; +}; /** * * Hashes the given message. The data will be UTF-8 HEX decoded and enveloped as follows: "\x19Ethereum Signed Message:\n" + message.length + message and hashed using keccak256. * - * @param message A message to hash, if its HEX it will be UTF8 decoded. + * @param message - A message to hash, if its HEX it will be UTF8 decoded. * @returns The hashed message * ```ts * hashMessage("Hello world") @@ -77,11 +105,14 @@ export const hashMessage = (message: string): string => { const messageBytes = hexToBytes(messageHex); - const preamble = `\x19Ethereum Signed Message:\n${messageBytes.length}`; + const preamble = Buffer.from( + `\x19Ethereum Signed Message:\n${messageBytes.byteLength}`, + 'utf8', + ); - const ethMessage = Buffer.concat([Buffer.from(preamble), Buffer.from(messageBytes)]); + const ethMessage = Buffer.concat([preamble, messageBytes]); - return `0x${Buffer.from(keccak256(ethMessage)).toString('hex')}`; + return sha3Raw(ethMessage); // using keccak in web3-utils.sha3Raw instead of SHA3 (NIST Standard) as both are different }; /** @@ -103,31 +134,30 @@ export const hashMessage = (message: string): string => { * } * ``` */ -export const sign = (data: string, privateKey: HexString): SignResult => { - const privateKeyParam = privateKey.startsWith('0x') ? privateKey.substring(2) : privateKey; - - if (!isHexString32Bytes(privateKeyParam, false)) { - throw new PrivateKeyLengthError(); - } +export const sign = (data: string, privateKey: Bytes): SignResult => { + const privateKeyBuffer = parseAndValidatePrivateKey(privateKey); const hash = hashMessage(data); - const signObj = ecdsaSign( - Buffer.from(hash.substring(2), 'hex'), - Buffer.from(privateKeyParam, 'hex'), - ); + const [signature, recoverId] = signSync(hash.substring(2), privateKeyBuffer, { + // Makes signatures compatible with libsecp256k1 + recovered: true, + + // Returned signature should be in DER format ( non compact ) + der: false, + }); - const r = Buffer.from(signObj.signature.slice(0, 32)); - const s = Buffer.from(signObj.signature.slice(32, 64)); - const v = signObj.recid + 27; + const r = Buffer.from(signature.slice(0, 32)); + const s = Buffer.from(signature.slice(32, 64)); + const v = recoverId + 27; return { message: data, messageHash: hash, - v: `0x${v.toString(16)}`, - r: `0x${r.toString('hex')}`, - s: `0x${s.toString('hex')}`, - signature: `0x${Buffer.from(signObj.signature).toString('hex')}${v.toString(16)}`, + v: numberToHex(v), + r: bytesToHex(r), + s: bytesToHex(s), + signature: `0x${Buffer.from(signature).toString('hex')}${v.toString(16)}`, }; }; @@ -234,7 +264,7 @@ export const signTransaction = async ( } const rawTx = bytesToHex(signedTx.serialize()); - const txHash = keccak256(hexToBytes(rawTx)); + const txHash = sha3Raw(rawTx); // using keccak in web3-utils.sha3Raw instead of SHA3 (NIST Standard) as both are different return { messageHash: bytesToHex(Buffer.from(signedTx.getMessageToSign(true))), @@ -302,10 +332,10 @@ export const recover = ( const v = signature.substring(V_INDEX); // 0x + r + s + v - const ecPublicKey = ecdsaRecover( + const ecPublicKey = recoverPublicKey( + Buffer.from(hashedMessage.substring(2), 'hex'), Buffer.from(signature.substring(2, V_INDEX), 'hex'), parseInt(v, 16) - 27, - Buffer.from(hashedMessage.substring(2), 'hex'), false, ); @@ -360,29 +390,20 @@ const uuidV4 = (): string => { * > "0xEB014f8c8B418Db6b45774c326A0E64C78914dC0" * ``` */ -export const privateKeyToAddress = (privateKey: string | Buffer): string => { - if (!(isString(privateKey) || isBuffer(privateKey))) { - throw new InvalidPrivateKeyError(); - } +export const privateKeyToAddress = (privateKey: Bytes): string => { + const privateKeyBuffer = parseAndValidatePrivateKey(privateKey); - const stringPrivateKey = Buffer.isBuffer(privateKey) - ? Buffer.from(privateKey).toString('hex') - : privateKey; + // Get public key from private key in compressed format + const publicKey = getPublicKey(privateKeyBuffer); - const stringPrivateKeyNoPrefix = stringPrivateKey.startsWith('0x') - ? stringPrivateKey.slice(2) - : stringPrivateKey; - - if (!isHexString32Bytes(stringPrivateKeyNoPrefix, false)) { - throw new PrivateKeyLengthError(); - } + // Uncompressed ECDSA public key contains the prefix `0x04` which is not used in the Ethereum public key + const publicKeyHash = sha3Raw(publicKey.slice(1)); - const publicKey = getPublicKey(stringPrivateKeyNoPrefix); + // The hash is returned as 256 bits (32 bytes) or 64 hex characters + // To get the address, take the last 20 bytes of the public hash + const address = publicKeyHash.slice(-40); - const publicKeyString = `0x${publicKey.slice(2)}`; - const publicHash = sha3Raw(publicKeyString); - const publicHashHex = bytesToHex(publicHash); - return toChecksumAddress(publicHashHex.slice(-40)); // To get the address, take the last 20 bytes of the public hash + return toChecksumAddress(`0x${address}`); }; /** @@ -460,21 +481,11 @@ export const privateKeyToAddress = (privateKey: string | Buffer): string => { *``` */ export const encrypt = async ( - privateKey: HexString, + privateKey: Bytes, password: string | Buffer, options?: CipherOptions, ): Promise => { - if (!(isString(privateKey) || isBuffer(privateKey))) { - throw new InvalidPrivateKeyError(); - } - - const stringPrivateKey = Buffer.isBuffer(privateKey) - ? Buffer.from(privateKey).toString('hex') - : privateKey; - - if (!isHexString32Bytes(stringPrivateKey)) { - throw new PrivateKeyLengthError(); - } + const privateKeyBuffer = parseAndValidatePrivateKey(privateKey); // if given salt or iv is a string, convert it to a Uint8Array let salt; @@ -546,10 +557,8 @@ export const encrypt = async ( throw new InvalidKdfError(); } - const cipherKey = Buffer.from(stringPrivateKey.replace('0x', ''), 'hex'); - const cipher = await createCipheriv( - cipherKey, + privateKeyBuffer, Buffer.from(derivedKey.slice(0, 16)), initializationVector, 'aes-128-ctr', @@ -562,7 +571,7 @@ export const encrypt = async ( return { version: 3, id: uuidV4(), - address: privateKeyToAddress(stringPrivateKey).toLowerCase().replace('0x', ''), + address: privateKeyToAddress(privateKeyBuffer).toLowerCase().replace('0x', ''), crypto: { ciphertext, cipherparams: { @@ -596,19 +605,19 @@ export const encrypt = async ( * } * ``` */ -export const privateKeyToAccount = (privateKey: string | Buffer): Web3Account => { - const pKey = Buffer.isBuffer(privateKey) ? Buffer.from(privateKey).toString('hex') : privateKey; +export const privateKeyToAccount = (privateKey: Bytes): Web3Account => { + const privateKeyBuffer = parseAndValidatePrivateKey(privateKey); return { - address: privateKeyToAddress(pKey), - privateKey: pKey, + address: privateKeyToAddress(privateKeyBuffer), + privateKey: bytesToHex(privateKeyBuffer), signTransaction: (_tx: Record) => { throw new SignerError('Do not have network access to sign the transaction'); }, sign: (data: Record | string) => - sign(typeof data === 'string' ? data : JSON.stringify(data), pKey), + sign(typeof data === 'string' ? data : JSON.stringify(data), privateKeyBuffer), encrypt: async (password: string, options?: Record) => { - const data = await encrypt(pKey, password, options); + const data = await encrypt(privateKeyBuffer, password, options); return JSON.stringify(data); }, diff --git a/packages/web3-eth-accounts/test/fixtures/account.ts b/packages/web3-eth-accounts/test/fixtures/account.ts index b79a406d2a7..63048fb18b8 100644 --- a/packages/web3-eth-accounts/test/fixtures/account.ts +++ b/packages/web3-eth-accounts/test/fixtures/account.ts @@ -28,6 +28,33 @@ import { import { sign, signTransaction, encrypt } from '../../src/account'; import { CipherOptions, KeyStore } from '../../src/types'; +export const validPrivateKeyToAddressData: [string, string][] = [ + [ + '0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709', + '0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01', + ], + [ + '0x9e93921f9bca358a96aa66efcccbde12850473be95f63c1453e29656feafeb35', + '0x118C2E5F57FD62C2B5b46a5ae9216F4FF4011a07', + ], + [ + '0xf44e0436edb0afd26b09f7b9f1e7a280d2365fc530aebccf893f1158a449d20a', + '0x8824eEA7A9FF8E051e63ACAc443460151CB6fd92', + ], + [ + '0xf4a2b939592564feb35ab10a8e04f6f2fe0943579fb3c9c33505298978b74893', + '0xd5e099c71B797516c10ED0F0d895f429C2781142', + ], +]; + +export const invalidPrivateKeyToAddressData: [ + any, + PrivateKeyLengthError | InvalidPrivateKeyError, +][] = [ + ['', new InvalidPrivateKeyError()], + [Buffer.from([]), new PrivateKeyLengthError()], +]; + export const validPrivateKeytoAccountData: [string, any][] = [ [ '0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709', @@ -52,6 +79,17 @@ export const validPrivateKeytoAccountData: [string, any][] = [ ]; export const signatureRecoverData: [string, any][] = [ + [ + 'Some long text with integers 1233 and special characters and unicode \u1234 as well.', + { + address: '0x6E599DA0bfF7A6598AC1224E4985430Bf16458a4', + privateKey: '0xcb89ec4b01771c6c8272f4c0aafba2f8ee0b101afb22273b786939a8af7c1912', + data: 'Some long text with integers 1233 and special characters and unicode \u1234 as well.', + // signature done with personal_sign + signature: + '0x2ac888726c80494b80b63996455d109aef5db27e673dd92f277ac6e48dc300db3dfc7549744c2a33a03a2eaa0f2837f54c5951b80d5e05257d605bc695c2ae7f1c', + }, + ], [ 'Some data', { @@ -129,7 +167,7 @@ export const invalidPrivateKeytoAccountData: [ any, PrivateKeyLengthError | InvalidPrivateKeyError, ][] = [ - ['', new PrivateKeyLengthError()], + ['', new InvalidPrivateKeyError()], [Buffer.from([]), new PrivateKeyLengthError()], ]; @@ -392,3 +430,13 @@ export const invalidDecryptData: [[any, string], InvalidKdfError | KeyDerivation new KeyDerivationError(), ], ]; + +export const validHashMessageData: [string, string][] = [ + ['🤗', '0x716ce69c5d2d629c168bc02e24a961456bdc5a362d366119305aea73978a0332'], + [ + 'Some long text with integers 1233 and special characters and unicode \u1234 as well.', + '0xff21294f27c6b1e416215feb0b0b904c552c874c4e11b2314dd3afc1714ed8a8', + ], + ['non utf8 string', '0x8862c6a425a83c082216090e4f0e03b64106189e93c29b11d0112e77b477cce2'], + ['', '0x5f35dce98ba4fba25530a026ed80b2cecdaa31091ba4958b99b52ea1d068adad'], +]; diff --git a/packages/web3-eth-accounts/test/unit/account.test.ts b/packages/web3-eth-accounts/test/unit/account.test.ts index 38ec5a52c0f..666bfcf03be 100644 --- a/packages/web3-eth-accounts/test/unit/account.test.ts +++ b/packages/web3-eth-accounts/test/unit/account.test.ts @@ -16,29 +16,33 @@ along with web3.js. If not, see . */ import { TransactionFactory } from '@ethereumjs/tx'; +import { Address, isHexStrict } from 'web3-utils'; import { Web3ValidatorError } from 'web3-validator'; -import { isHexStrict, Address, utf8ToHex } from 'web3-utils'; import { create, + decrypt, + encrypt, + hashMessage, privateKeyToAccount, - signTransaction, + privateKeyToAddress, + recover, recoverTransaction, - hashMessage, sign, - recover, - encrypt, - decrypt, + signTransaction, } from '../../src/account'; import { + invalidDecryptData, + invalidEncryptData, + invalidKeyStore, + invalidPrivateKeytoAccountData, + invalidPrivateKeyToAddressData, signatureRecoverData, transactionsTestData, - validPrivateKeytoAccountData, - invalidPrivateKeytoAccountData, - validEncryptData, validDecryptData, - invalidDecryptData, - invalidKeyStore, - invalidEncryptData, + validEncryptData, + validHashMessageData, + validPrivateKeytoAccountData, + validPrivateKeyToAddressData, } from '../fixtures/account'; describe('accounts', () => { @@ -56,6 +60,20 @@ describe('accounts', () => { }); }); + describe('privateKeyToAddress', () => { + describe('valid cases', () => { + it.each(validPrivateKeyToAddressData)('%s', (input, output) => { + expect(privateKeyToAddress(input)).toEqual(output); + }); + }); + + describe('invalid cases', () => { + it.each(invalidPrivateKeyToAddressData)('%s', (input, output) => { + expect(() => privateKeyToAddress(input)).toThrow(output); + }); + }); + }); + describe('privateKeyToAccount', () => { describe('valid cases', () => { it.each(validPrivateKeytoAccountData)('%s', (input, output) => { @@ -103,27 +121,24 @@ describe('accounts', () => { }); describe('Hash Message', () => { - it('should hash data correctly using an emoji character', () => { - const message = '🤗'; - const dataHash = '0x716ce69c5d2d629c168bc02e24a961456bdc5a362d366119305aea73978a0332'; - - const hashedMessage = hashMessage(message); - expect(hashedMessage).toEqual(dataHash); - - const hashedMessageHex = hashMessage(utf8ToHex(message)); - expect(hashedMessageHex).toEqual(dataHash); + it.each(validHashMessageData)('%s', (message, hash) => { + expect(hashMessage(message)).toEqual(hash); }); }); describe('Sign Message', () => { - it.each(signatureRecoverData)('sign test %s', (data, testObj) => { - const result = sign(data, testObj.privateKey); - expect(result.signature).toEqual(testObj.signature); + describe('sign', () => { + it.each(signatureRecoverData)('%s', (data, testObj) => { + const result = sign(data, testObj.privateKey); + expect(result.signature).toEqual(testObj.signature); + }); }); - it.each(signatureRecoverData)('recover test %s', (data, testObj) => { - const address = recover(data, testObj.signature); - expect(address).toEqual(testObj.address); + describe('recover', () => { + it.each(signatureRecoverData)('%s', (data, testObj) => { + const address = recover(data, testObj.signature); + expect(address).toEqual(testObj.address); + }); }); }); @@ -165,7 +180,7 @@ describe('accounts', () => { const result = await decrypt(keystore, input[1]); expect(JSON.stringify(result)).toEqual( - JSON.stringify(privateKeyToAccount(input[3].slice(2))), + JSON.stringify(privateKeyToAccount(input[3])), ); const keystoreString = JSON.stringify(keystore); @@ -173,7 +188,7 @@ describe('accounts', () => { const stringResult = await decrypt(keystoreString, input[1], true); expect(JSON.stringify(stringResult)).toEqual( - JSON.stringify(privateKeyToAccount(input[3].slice(2))), + JSON.stringify(privateKeyToAccount(input[3])), ); }); }); diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index 3800e10a257..8111b24d807 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -42,6 +42,6 @@ "dependencies": { "web3-errors": "1.0.0-alpha.0", "web3-validator": "^0.1.0-alpha.0", - "ethereum-cryptography": "^1.0.3" + "ethereum-cryptography": "^1.1.0" } } diff --git a/packages/web3-validator/package.json b/packages/web3-validator/package.json index f1758ed9220..95399aa10e3 100644 --- a/packages/web3-validator/package.json +++ b/packages/web3-validator/package.json @@ -28,7 +28,7 @@ }, "dependencies": { "ajv": "^8.8.2", - "ethereum-cryptography": "^0.2.1" + "ethereum-cryptography": "^1.1.0" }, "devDependencies": { "@types/jest": "^27.0.3", diff --git a/yarn.lock b/yarn.lock index 33a55938446..213aa9ac467 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1686,25 +1686,20 @@ resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.14.1.tgz#155ef21065427901994e765da8a0ba0eaae8b8bd" integrity sha512-6Wci+Tp3CgPt/B9B0a3J4s3yMgLNSku6w5TV6mN+61C71UqsRBv2FUibBf3tPGlNxebgPHMEUzKpb1ggE8KCKw== -"@noble/hashes@1.0.0", "@noble/hashes@~1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.0.0.tgz#d5e38bfbdaba174805a4e649f13be9a9ed3351ae" - integrity sha512-DZVbtY62kc3kkBtMHqwCOfXrT/hnoORy5BJ4+HU1IR59X0KWAOqsfzQPcUl/lQLlG7qXbe/fZ3r/emxtAl+sqg== - -"@noble/hashes@^0.4.4": - version "0.4.5" - resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-0.4.5.tgz#f69a963b0c59c1145bc5aca1f3eef58a48bf9a59" - integrity sha512-oK/2b9gHb1CfiFwpPHQs010WgROn4ioilT7TFwxMVwuDaXEJP3QPhyedYbOpgM4JDBgT9n5gaispBQlkaAgT6g== +"@noble/hashes@1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.1.1.tgz#c056d9b7166c1e7387a7453c2aff199bf7d88e5f" + integrity sha512-Lkp9+NijmV7eSVZqiUvt3UCuuHeJpUVmRrvh430gyJjJiuJMqkeHf6/A9lQ/smmbWV/0spDeJscscPzyB4waZg== -"@noble/secp256k1@1.5.5", "@noble/secp256k1@~1.5.2": - version "1.5.5" - resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.5.5.tgz#315ab5745509d1a8c8e90d0bdf59823ccf9bcfc3" - integrity sha512-sZ1W6gQzYnu45wPrWx8D3kwI2/U29VYTx9OjbDAd7jwRItJ0cSTMPRL/C8AWZFn9kWFLQGqEXVEE86w4Z8LpIQ== +"@noble/hashes@~1.1.1": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.1.2.tgz#e9e035b9b166ca0af657a7848eb2718f0f22f183" + integrity sha512-KYRCASVTv6aeUi1tsF8/vpyR7zpfs3FUzy2Jqm+MU+LmUKhQ0y2FpfwqkCcxSg2ua4GALJd8k2R76WxwZGbQpA== -"@noble/secp256k1@^1.3.3": - version "1.3.4" - resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.3.4.tgz#158ded712d09237c0d3428be60dc01ce8ebab9fb" - integrity sha512-ZVRouDO5mbdCiDg4zCd3ZZABduRtpy4tCnB33Gh9upHe9tRzpiqbRSN1VTjrj/2g8u2c6MBi0YLNnNQpBYOiWg== +"@noble/secp256k1@1.6.0", "@noble/secp256k1@~1.6.0": + version "1.6.0" + resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.6.0.tgz#602afbbfcfb7e169210469b697365ef740d7e930" + integrity sha512-DWSsg8zMHOYMYBqIQi96BQuthZrp98LCeMNcUOaffCIVYQ5yxDbNikLF+H7jEnmNNmXbtVic46iCuVWzar+MgA== "@nodelib/fs.scandir@2.1.5": version "2.1.5" @@ -1903,27 +1898,27 @@ resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.6.0.tgz#c91cf64bc27f573836dba4122758b4743418c1b3" integrity sha512-8vi4d50NNya/bQqCmaVzvHNmwHvS0OBKb7HNtuNwEE3scXWrP31fKQoGxNMT+KbzmrNZzatE3QK5p2gFONI/hg== -"@scure/base@~1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.0.0.tgz#109fb595021de285f05a7db6806f2f48296fcee7" - integrity sha512-gIVaYhUsy+9s58m/ETjSJVKHhKTBMmcRb9cEV5/5dwvfDlfORjKrFsDeDHWRrm6RjcPvCLZFwGJjAjLj1gg4HA== +"@scure/base@~1.1.0": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938" + integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA== -"@scure/bip32@1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.0.1.tgz#1409bdf9f07f0aec99006bb0d5827693418d3aa5" - integrity sha512-AU88KKTpQ+YpTLoicZ/qhFhRRIo96/tlb+8YmDDHR9yiKVjSsFZiefJO4wjS2PMTkz5/oIcw84uAq/8pleQURA== +"@scure/bip32@1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.1.0.tgz#dea45875e7fbc720c2b4560325f1cf5d2246d95b" + integrity sha512-ftTW3kKX54YXLCxH6BB7oEEoJfoE2pIgw7MINKAs5PsS6nqKPuKk1haTF/EuHmYqG330t5GSrdmtRuHaY1a62Q== dependencies: - "@noble/hashes" "~1.0.0" - "@noble/secp256k1" "~1.5.2" - "@scure/base" "~1.0.0" + "@noble/hashes" "~1.1.1" + "@noble/secp256k1" "~1.6.0" + "@scure/base" "~1.1.0" -"@scure/bip39@1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.0.0.tgz#47504e58de9a56a4bbed95159d2d6829fa491bb0" - integrity sha512-HrtcikLbd58PWOkl02k9V6nXWQyoa7A0+Ek9VF7z17DDk9XZAFUcIdqfh0jJXLypmizc5/8P6OxoUeKliiWv4w== +"@scure/bip39@1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.1.0.tgz#92f11d095bae025f166bef3defcc5bf4945d419a" + integrity sha512-pwrPOS16VeTKg98dYXQyIjJEcWfz7/1YJIwxUEPFfQPtc86Ym/1sVgQ2RLoD43AazMk2l/unK4ITySSpW2+82w== dependencies: - "@noble/hashes" "~1.0.0" - "@scure/base" "~1.0.0" + "@noble/hashes" "~1.1.1" + "@scure/base" "~1.1.0" "@sinonjs/commons@^1.7.0": version "1.8.3" @@ -4881,24 +4876,15 @@ ethereum-cryptography@^0.1.3: secp256k1 "^4.0.1" setimmediate "^1.0.5" -ethereum-cryptography@^0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-0.2.1.tgz#7a2cce5c47157eb6992229cf26ccd889d5ee4754" - integrity sha512-hZkrGoL/LkL8OtrXJkCsNJkOs7ONplB1wvAq8pfagpHC5KVGJHWx2xFbRGuWP2zbMKBdxKBcbzMOG4v/ejSulw== - dependencies: - "@noble/hashes" "^0.4.4" - "@noble/secp256k1" "^1.3.3" - micro-base "^0.10.0" - -ethereum-cryptography@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-1.0.3.tgz#b1f8f4e702434b2016248dbb2f9fdd60c54772d8" - integrity sha512-NQLTW0x0CosoVb/n79x/TRHtfvS3hgNUPTUSCu0vM+9k6IIhHFFrAOJReneexjZsoZxMjJHnJn4lrE8EbnSyqQ== +ethereum-cryptography@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-1.1.0.tgz#7048d184ff365a5255ced5cc9eb7682a273c4db7" + integrity sha512-wyNVTBR4wIR2yoXdMv4Qt44mTVBpPgSW/DQCTmNO6nQluwpyrAIvmL4mxPbziFuc6VWJQa3rwUxn0nUFU03nyQ== dependencies: - "@noble/hashes" "1.0.0" - "@noble/secp256k1" "1.5.5" - "@scure/bip32" "1.0.1" - "@scure/bip39" "1.0.0" + "@noble/hashes" "1.1.1" + "@noble/secp256k1" "1.6.0" + "@scure/bip32" "1.1.0" + "@scure/bip39" "1.1.0" ethereum-protocol@^1.0.1: version "1.0.1" @@ -7768,11 +7754,6 @@ methods@~1.1.2: resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4= -micro-base@^0.10.0: - version "0.10.0" - resolved "https://registry.yarnpkg.com/micro-base/-/micro-base-0.10.0.tgz#2a324c7836920b2cbca674f46d0644b7e56e4012" - integrity sha512-huKVznyEDZVO7pcYoVZMBR6prkxzkJSTT96T2tyHY1Wk3Sywcpb7NwxHAwKf/fmfqsdFuY2rDRR3UYkY6Uh9LQ== - micromatch@^3.1.10: version "3.1.10" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" @@ -9494,7 +9475,7 @@ scrypt-js@^3.0.0, scrypt-js@^3.0.1: resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-3.0.1.tgz#d314a57c2aef69d1ad98a138a21fe9eafa9ee312" integrity sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA== -secp256k1@^4.0.1, secp256k1@^4.0.2: +secp256k1@^4.0.1: version "4.0.2" resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.2.tgz#15dd57d0f0b9fdb54ac1fa1694f40e5e9a54f4a1" integrity sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg== From b1c373269a87dd3af72b1f62ef9bbd03acd315cb Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Mon, 11 Jul 2022 14:11:22 +0300 Subject: [PATCH 15/18] add net to web3 eth interface (#5217) --- packages/web3/src/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/web3/src/types.ts b/packages/web3/src/types.ts index 29ee2ea95bc..aed712cbdac 100644 --- a/packages/web3/src/types.ts +++ b/packages/web3/src/types.ts @@ -40,6 +40,7 @@ import { } from 'web3-eth-accounts'; import Contract, { ContractInitOptions } from 'web3-eth-contract'; import { ENS } from 'web3-eth-ens'; +import Net from 'web3-net'; import { Iban } from 'web3-eth-iban'; import { Address, Bytes } from 'web3-utils'; @@ -66,6 +67,7 @@ export interface Web3EthInterface extends Eth { */ Contract: Web3ContractConstructor; Iban: typeof Iban; + net: Net; ens: ENS; abi: { encodeEventSignature: typeof encodeFunctionSignature; From 6f85fe00dd5087c920aed24a40b1c60b43d18d9f Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Mon, 11 Jul 2022 17:08:47 +0300 Subject: [PATCH 16/18] web3-common/core defaults documentation (#5198) * Init commit with defaultAccount * Add some more properties * Add more properties * Refactor docs * Apply some changes from reviews --- packages/web3-core/src/web3_config.ts | 125 +++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) diff --git a/packages/web3-core/src/web3_config.ts b/packages/web3-core/src/web3_config.ts index b3ad62b380e..9981b1c7fbd 100644 --- a/packages/web3-core/src/web3_config.ts +++ b/packages/web3-core/src/web3_config.ts @@ -94,10 +94,21 @@ export abstract class Web3Config Object.assign(this._config, options); } + /** + * The `handleRevert` options property returns the revert reason string if enabled for the following methods: + * - web3.eth.sendTransaction() + * - web3.eth.call() + * - myContract.methods.myMethod().call() + * - myContract.methods.myMethod().send() + * Default is `false`. + */ public get handleRevert() { return this._config.handleRevert; } + /** + * Will set the handleRevert + */ public set handleRevert(val) { this.emit(Web3ConfigEvent.CONFIG_CHANGE, { name: 'handleRevert', @@ -107,10 +118,19 @@ export abstract class Web3Config this._config.handleRevert = val; } + /** + * This default address is used as the default `from` property, if no `from` property is specified in for the following methods: + * - web3.eth.sendTransaction() + * - web3.eth.call() + * - myContract.methods.myMethod().call() + * - myContract.methods.myMethod().send() + */ public get defaultAccount() { return this._config.defaultAccount; } - + /** + * Will set the default account. + */ public set defaultAccount(val) { this.emit(Web3ConfigEvent.CONFIG_CHANGE, { name: 'defaultAccount', @@ -120,10 +140,30 @@ export abstract class Web3Config this._config.defaultAccount = val; } + /** + * The default block is used for certain methods. You can override it by passing in the defaultBlock as last parameter. The default value is `"latest"`. + * - web3.eth.getBalance() + * - web3.eth.getCode() + * - web3.eth.getTransactionCount() + * - web3.eth.getStorageAt() + * - web3.eth.call() + * - myContract.methods.myMethod().call() + * + * @returns {BlockNumberOrTag} + */ public get defaultBlock() { return this._config.defaultBlock; } + /** + * Will set the default block. + * + * @param {BlockNumberOrTag} val + * - A block number + * - `"earliest"` - String: The genesis block + * - `"latest"` - String: The latest block (current head of the blockchain) + * - `"pending"` - String: The currently mined block (including pending transactions) + */ public set defaultBlock(val) { this.emit(Web3ConfigEvent.CONFIG_CHANGE, { name: 'defaultBlock', @@ -133,10 +173,17 @@ export abstract class Web3Config this._config.defaultBlock = val; } + /** + * The `transactionBlockTimeout` is used over socket-based connections. This option defines the amount of new blocks it should wait until the first confirmation happens, otherwise the PromiEvent rejects with a timeout error. + * Default is `50`. + */ public get transactionBlockTimeout() { return this._config.transactionBlockTimeout; } + /** + * Will set the transactionBlockTimeout. + */ public set transactionBlockTimeout(val) { this.emit(Web3ConfigEvent.CONFIG_CHANGE, { name: 'transactionBlockTimeout', @@ -146,10 +193,17 @@ export abstract class Web3Config this._config.transactionBlockTimeout = val; } + /** + * This defines the number of blocks it requires until a transaction is considered confirmed. + * Default is `24`. + */ public get transactionConfirmationBlocks() { return this._config.transactionConfirmationBlocks; } + /** + * Will set the transactionConfirmationBlocks. + */ public set transactionConfirmationBlocks(val) { this.emit(Web3ConfigEvent.CONFIG_CHANGE, { name: 'transactionConfirmationBlocks', @@ -160,10 +214,17 @@ export abstract class Web3Config this._config.transactionConfirmationBlocks = val; } + /** + * Used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. + * Default is `1000` ms. + */ public get transactionPollingInterval() { return this._config.transactionPollingInterval; } + /** + * Will set the transactionPollingInterval. + */ public set transactionPollingInterval(val) { this.emit(Web3ConfigEvent.CONFIG_CHANGE, { name: 'transactionPollingInterval', @@ -176,21 +237,34 @@ export abstract class Web3Config this.transactionReceiptPollingInterval = val; this.transactionConfirmationPollingInterval = val; } - + /** + * Used over HTTP connections. This option defines the number of seconds Web3 will wait for a receipt which confirms that a transaction was mined by the network. Note: If this method times out, the transaction may still be pending. + * Default is `750` ms. + */ public get transactionPollingTimeout() { return this._config.transactionPollingTimeout; } + /** + * Will set the transactionPollingTimeout. + */ public set transactionPollingTimeout(val) { this._triggerConfigChange('transactionPollingTimeout', val); this._config.transactionPollingTimeout = val; } + /** + * The `transactionPollingInterval` is used over HTTP connections. This option defines the number of seconds between Web3 calls for a receipt which confirms that a transaction was mined by the network. + * Default is `undefined` + */ public get transactionReceiptPollingInterval() { return this._config.transactionReceiptPollingInterval; } + /** + * Will set the transactionReceiptPollingInterval + */ public set transactionReceiptPollingInterval(val) { this.emit(Web3ConfigEvent.CONFIG_CHANGE, { name: 'transactionReceiptPollingInterval', @@ -215,10 +289,17 @@ export abstract class Web3Config this._config.transactionConfirmationPollingInterval = val; } + /** + * The blockHeaderTimeout is used over socket-based connections. This option defines the amount seconds it should wait for “newBlockHeaders” event before falling back to polling to fetch transaction receipt. + * Default is `10` seconds. + */ public get blockHeaderTimeout() { return this._config.blockHeaderTimeout; } + /** + * Will set the blockHeaderTimeout + */ public set blockHeaderTimeout(val) { this._triggerConfigChange('blockHeaderTimeout', val); @@ -255,20 +336,60 @@ export abstract class Web3Config this._config.defaultChain = val; } + /** + * Will return the default hardfork. Default is `london` + * The default hardfork property can be one of the following: + * - `chainstart` + * - `homestead` + * - `dao` + * - `tangerineWhistle` + * - `spuriousDragon` + * - `byzantium` + * - `constantinople` + * - `petersburg` + * - `istanbul` + * - `berlin` + * - `london` + * - 'arrowGlacier', + * - 'tangerineWhistle', + * - 'muirGlacier' + * + */ public get defaultHardfork() { return this._config.defaultHardfork; } + /** + * Will set the default hardfork. + * + */ public set defaultHardfork(val) { this._triggerConfigChange('defaultHardfork', val); this._config.defaultHardfork = val; } + /** + * + * Will get the default common property + * The default common property does contain the following Common object: + * - `customChain` - `Object`: The custom chain properties + * - `name` - `string`: (optional) The name of the chain + * - `networkId` - `number`: Network ID of the custom chain + * - `chainId` - `number`: Chain ID of the custom chain + * - `baseChain` - `string`: (optional) mainnet, goerli, kovan, rinkeby, or ropsten + * - `hardfork` - `string`: (optional) chainstart, homestead, dao, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul, berlin, or london + * Default is `undefined`. + * + */ public get defaultCommon() { return this._config.defaultCommon; } + /** + * Will set the default common property + * + */ public set defaultCommon(val) { this._triggerConfigChange('defaultCommon', val); From 7a3581dc5f7e408d496a7c93e74fcfd7d24a8f6e Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 7 Jul 2022 18:02:18 +0200 Subject: [PATCH 17/18] Upgrade ethereum-cryptography to 1.0 (#5211) * :arrow_up: Update ethereum-cryptography package * Apply suggestions from code review Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> * :art: Update the code as per feedback Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> From e595585cf6d612a6a0c51b928c5bf2c3f360e0e5 Mon Sep 17 00:00:00 2001 From: Nikos Iliakis Date: Mon, 11 Jul 2022 17:08:47 +0300 Subject: [PATCH 18/18] web3-common/core defaults documentation (#5198) * Init commit with defaultAccount * Add some more properties * Add more properties * Refactor docs * Apply some changes from reviews