|
2 | 2 | sidebar_position: 18 |
3 | 3 | --- |
4 | 4 |
|
| 5 | +# Migrate from v5 to v6 |
| 6 | + |
| 7 | +This document only covers the features present in v5 which have changed in some significant way in v6. |
| 8 | +If you encounter any missing changes, please let us know and we will update this guide. |
| 9 | + |
| 10 | +## Transaction response |
| 11 | + |
| 12 | +When you send a transaction, the response type has changed. |
| 13 | +Previously, the response was just the transaction hash value. Now, the response is an object including many other data. |
| 14 | +This has an impact on `provider.waitForTransaction()` : |
| 15 | + |
| 16 | +```typescript |
| 17 | +const response = await ethContract.approve(swapContractAddress, cairo.uint256(100000)); |
| 18 | +// v5 |
| 19 | +const transactionReceipt = await provider.waitForTransaction(response); |
| 20 | + |
| 21 | +// v6 |
| 22 | +const transactionReceipt = await provider.waitForTransaction(response.transaction_hash); |
| 23 | +``` |
| 24 | + |
| 25 | +## Long strings |
| 26 | + |
| 27 | +Starknet.js v6 is compatible with Cairo v2.4.0. It means that the long strings (>31 characters) are automatically handled and converted to the Cairo `ByteArray` type. |
| 28 | +So, the command to convert a long string to an array of felts (for Cairo 0 contracts for example) has changed : |
| 29 | + |
| 30 | +```typescript |
| 31 | +// v5 |
| 32 | +const param: BigNumberish[] = CallData.compile("http://addressOfMyERC721pictures/storage/image1.jpg"); |
| 33 | +// v6 |
| 34 | +const param: BigNumberish[] = CallData.compile(shortString.splitLongString("http://addressOfMyERC721pictures/storage/image1.jpg")); |
| 35 | +``` |
| 36 | + |
| 37 | +## Fees |
| 38 | + |
| 39 | +All functions related to gas price and estimation of fees have changed their output types. |
| 40 | +For example, if you read the content of a block, the ETH gasPrice was straightforward to read. With v6, it's now more nested : |
| 41 | + |
| 42 | +```typescript |
| 43 | +const resp: GetBlockResponse = await myProvider.getBlock("latest"); |
| 44 | +// v5 |
| 45 | +const gasPrice = resp.gas_price; |
| 46 | +// v6 |
| 47 | +const gasPrice = resp.l1_gas_price.price_in_wei; |
| 48 | +``` |
| 49 | + |
| 50 | +Other example for `estimateDeclareFee()`, where the object response has changed : |
| 51 | + |
| 52 | +```typescript |
| 53 | +const fee = await account0.estimateDeclareFee({ contract: compiledContract }); |
| 54 | +// v5 response |
| 55 | +fee = { |
| 56 | + overall_fee: 247700000000000n, |
| 57 | + gas_consumed: 2477n, |
| 58 | + gas_price: 100000000000n, |
| 59 | + suggestedMaxFee: 371550000000000n |
| 60 | +} |
| 61 | +// v6 response |
| 62 | +fee = { |
| 63 | + overall_fee: 247700000000000n, |
| 64 | + gas_consumed: 2477n, |
| 65 | + gas_price: 100000000000n, |
| 66 | + unit: undefined, |
| 67 | + suggestedMaxFee: 371550000000000n, |
| 68 | + resourceBounds: { |
| 69 | + l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' }, |
| 70 | + l1_gas: { max_amount: '0xaa4', max_price_per_unit: '0x22ecb25c00' } |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +So you have to adapt your code to all these new entries. Globally, pay attention of all the result types of methods that returns a response from the node. |
| 76 | + |
| 77 | +<br /> |
| 78 | +<br /> |
| 79 | +<br /> |
| 80 | +<hr> |
| 81 | +<hr> |
| 82 | + |
5 | 83 | # Migrate from v4 to v5 |
6 | 84 |
|
7 | 85 | This document only covers the features present in v4 which have changed in some significant way in v5. |
|
0 commit comments