web3 icon indicating copy to clipboard operation
web3 copied to clipboard

web3 migrate command

Open treeder opened this issue 5 years ago • 6 comments

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.

treeder avatar Apr 01 '19 22:04 treeder

@benbjohnson you might have some thoughts on this after doing the upgrade feature?

treeder avatar Apr 01 '19 22:04 treeder

  • 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?

jmank88 avatar Apr 01 '19 23:04 jmank88

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....

treeder avatar Apr 01 '19 23:04 treeder

It looks like getStorageAt only retrieves individual values, so you'd have to know all the keys for a map for example.

jmank88 avatar Apr 01 '19 23:04 jmank88

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.

treeder avatar Apr 02 '19 02:04 treeder

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.

benbjohnson avatar Apr 04 '19 15:04 benbjohnson