-
Notifications
You must be signed in to change notification settings - Fork 74
Add migration guide for Ethereum contracts (new IA) #1114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0ae4e1f
Add migration guide for Ethereum contracts to Polkadot Hub
nhussein11 966e77f
fix: llms
nhussein11 e2b8f45
fix: feedback
nhussein11 aa4a59c
fix
0xlukem 70dc027
fix
0xlukem c7e2e8f
fix
0xlukem 2e78833
add links
0xlukem 4b0b2e4
fix
0xlukem 4d488fd
Merge branch 'staging/product-ia' into nhussein11/add-migration-page
0xlukem acb09da
fix merge issues
0xlukem 9b2ff42
Update smart-contracts/for-eth-devs/migration.md
0xlukem 823e063
feedback
0xlukem 6eee309
Merge branch 'staging/product-ia' into nhussein11/add-migration-page
0xlukem 4854ba7
Update smart-contracts/for-eth-devs/migration.md
0xlukem 0e09fb6
change description
0xlukem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,150 @@ | ||
| TODO | ||
| --- | ||
| title: Migration FAQs and Considerations | ||
| description: Learn how to migrate your existing Ethereum contracts to the Polkadot Hub using REVM and PolkaVM. | ||
| categories: Smart Contracts | ||
| --- | ||
|
|
||
| # Migration FAQs and Considerations | ||
|
|
||
| ## Introduction | ||
|
|
||
| This guide helps Ethereum developers migrate their smart contracts to Polkadot Hub. Most contracts work without modifications on the REVM backend, while the PolkaVM backend offers enhanced performance with minimal adaptation for standard patterns. | ||
|
|
||
| ## Migration Considerations | ||
|
|
||
| Take into account the following considerations before migrating your contracts: | ||
|
|
||
| - Standard ERC-20, ERC-721, ERC-1155 tokens work without changes. | ||
| - DeFi protocols, DEXs, and AMMs migrate seamlessly. | ||
| - DAOs and governance contracts are fully compatible. | ||
| - Most Solidity contracts deploy identically to Ethereum. | ||
|
|
||
| ## Migration Checklist | ||
|
|
||
| Before migrating your contracts, review this checklist: | ||
|
|
||
| - Factory contracts using PVM bytecode need pre-uploaded dependencies. | ||
| - Contracts using `EXTCODECOPY` for runtime manipulation require review (for projects that will use PVM bytecode, not EVM bytecode). | ||
| - Replace `transfer()` and `send()` with proper reentrancy guards (for projects that will use PVM bytecode, not EVM bytecode). | ||
|
|
||
| ## Migration FAQs | ||
|
|
||
| ### Which backend should I choose? | ||
|
|
||
| - Choose REVM if you want: | ||
|
|
||
| - Zero-modification deployment of existing Ethereum contracts. | ||
| - Exact EVM behavior for audited code. | ||
| - Compatibility with tools that inspect EVM bytecode. | ||
| - Rapid deployment without optimization. | ||
|
|
||
| - Choose PolkaVM if you want: | ||
|
|
||
| - Better performance for computation-heavy applications. | ||
| - Lower execution costs for intensive operations. | ||
| - Access to next-generation smart contract features. | ||
|
|
||
| If you are unsure which to choose, start with REVM for immediate compatibility, then consider PolkaVM for performance optimization once deployed. | ||
|
|
||
| ### Do I need to rewrite my Solidity code? | ||
|
|
||
| No, for most contracts. Standard Solidity patterns work on both backends. | ||
|
|
||
| ### What about factory contracts? | ||
|
|
||
| - **REVM**: Factory contracts work identically to Ethereum with no changes needed. | ||
|
|
||
| The original factory pattern is: | ||
|
|
||
| ```solidity | ||
| contract TokenFactory { | ||
| function createToken(string memory name) public returns (address) { | ||
| // Creates new contract at runtime | ||
| Token newToken = new Token(name); | ||
| return address(newToken); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| - **PolkaVM**: Factory contracts require pre-uploading dependent contracts. | ||
|
|
||
| Here's how to adapt the original factory pattern: | ||
|
|
||
| ```solidity | ||
| contract TokenFactory { | ||
| // Reference pre-uploaded Token contract by hash | ||
| bytes32 public tokenCodeHash; | ||
|
|
||
| constructor(bytes32 _tokenCodeHash) { | ||
| tokenCodeHash = _tokenCodeHash; | ||
| } | ||
|
|
||
| function createToken(string memory name) public returns (address) { | ||
| // Instantiate from pre-uploaded code | ||
| Token newToken = new Token{salt: keccak256(abi.encode(name))}(name); | ||
| return address(newToken); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The deployment steps for PolkaVM factories are: | ||
|
|
||
| 1. Upload the contract code to the chain. | ||
| 2. Note the returned code hash. | ||
| 3. Deploy the Factory contract with the contract code hash. | ||
| 4. Factory can now instantiate contracts using the pre-uploaded code. | ||
|
|
||
| ### How do gas costs compare? | ||
|
|
||
| For more information on gas costs, see the [Gas Model](/smart-contracts/for-eth-devs/gas-model){target=\_blank} page. | ||
0xlukem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Which Solidity features are not supported? | ||
|
|
||
| For REVM, any Solidity feature will function smoothly without requiring changes or adaptations. For PVM, there are considerations, as was mentioned above. | ||
|
|
||
| For PolkaVM, there are some considerations: | ||
|
|
||
| - `EXTCODECOPY`: Only works in constructor code. | ||
| - Runtime code modification: Use on-chain constructors instead. | ||
| - **Gas stipends**: `address.send()` and `address.transfer()` don't provide reentrancy protection. | ||
| - **Unsupported operations**: `pc`, `extcodecopy`, `selfdestruct`, `blobhash`, and `blobbasefee` (blob-related operations). | ||
|
|
||
| ### How do I handle the existential deposit? | ||
|
|
||
| Polkadot requires accounts to maintain a minimum balance (existential deposit or ED) to remain active. | ||
|
|
||
| This is handled automatically for you: | ||
|
|
||
| - Balance queries via Ethereum RPC automatically deduct the ED. | ||
| - New account transfers include ED in transaction fees. | ||
| - Contract-to-contract transfers draw ED from the transaction signer. | ||
|
|
||
| You typically don't need to do anything special, but be aware: | ||
|
|
||
| - Accounts below ED threshold are automatically deleted. | ||
| - ED is around 0.01 DOT (varies by network). | ||
| - Your contracts don't need to manage this explicitly. | ||
|
|
||
| ### Can I use my existing development tools? | ||
|
|
||
| Yes. Both backends support: | ||
|
|
||
| - **Wallets**: [MetaMask](https://metamask.io/){target=\_blank}, [Talisman](https://talisman.xyz/){target=\_blank}, [SubWallet](https://www.subwallet.app/){target=\_blank} | ||
| - **Development frameworks**: [Hardhat](/smart-contracts/cookbook/smart-contracts/deploy-basic/hardhat/){target=\_blank}, [Foundry](/smart-contracts/cookbook/smart-contracts/deploy-basic/foundry/){target=\_blank}, [Remix](/smart-contracts/cookbook/smart-contracts/deploy-basic/remix/){target=\_blank} (just consider that for PVM bytecode, you will use the Polkadot version of the tooling) | ||
| - **Libraries**: [ethers.js](/smart-contracts/libraries/ethers-js/){target=\_blank}, [web3.js](/smart-contracts/libraries/web3-js/){target=\_blank}, [viem](/smart-contracts/libraries/viem/){target=\_blank} | ||
| - **Testing tools**: Your existing test suites work | ||
|
|
||
| Connect to Polkadot Hub's Ethereum JSON-RPC endpoint and use your familiar workflow. | ||
|
|
||
| ## Conclusion | ||
|
|
||
| Most Ethereum contracts migrate to Polkadot Hub with minimal or no changes. Use REVM for seamless compatibility or PolkaVM for enhanced performance. | ||
|
|
||
| There are a few key points to keep in mind during migration: | ||
|
|
||
| - Replace `transfer()` and `send()` with `.call{value}("")` and use reentrancy guards (for projects that will use PVM bytecode, not EVM bytecode). | ||
| - PolkaVM factory contracts using PVM bytecode need pre-uploaded dependencies. | ||
| - Don't hardcode gas values. | ||
| - Test thoroughly on [TestNet](/smart-contracts/connect/#__tabbed_1_1){target=\_blank} before mainnet deployment. | ||
|
|
||
| Your existing Solidity knowledge and tooling transfer directly to Polkadot Hub, making migration straightforward for standard smart contract patterns. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.