web3
web3 copied to clipboard
web3 migrate command
I'm not entirely sure how this could work, but imagine wanting to move to a new contract if you wanted to upgrade it (and didn't use an upgradeable contract). Or if you wanted to move from Ethereum to GoChain (or vice versa). This would move all the data and allow you to either use the existing contract code (if moving blockchains) or deploy new contract code with the same data.
@benbjohnson you might have some thoughts on this after doing the upgrade feature?
- Given that it is not possible to e.g. iterate over map keys, is it possible to even know the full state of a contract without first replaying its history? Could we replay the full history in an offline simulation, and then deploy that result via a single tx? Would it have to be a relatively costly constructor?
- Is it reasonable to expect users to reuse the same accounts on both chains? Or would we need to support some kind of mapping?
I believe you could get code with eth_getCode and potentially all the storage via eth_getStorageAt (guessing). Now I have no idea how you'd write that to the new contract storage though....
It looks like getStorageAt
only retrieves individual values, so you'd have to know all the keys for a map for example.
Alternatively, we could do it for contracts that do support such an iteration.
https://docs.openzeppelin.org/docs/token_erc721_erc721token#tokenByIndex
Too bad ERC-20's don't typically have something like this for all token holders.
Sorry for the late reply. I agree with @jmank88 that we wouldn't be able to fetch the data without replaying history. I also agree that data relating to addresses isn't going to migrate well across chains.