A quick [thread] on
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ±" title="Seedling" aria-label="Emoji: Seedling">v0.rooted.eth: a technique for redeploying new smart contract code to the same address that @ricmoo introduced yesterday.
Let& #39;s poke at it on mainnet...
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đŹ" title="Grimacing face" aria-label="Emoji: Grimacing face">
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đïž" title="Building construction" aria-label="Emoji: Building construction">
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ€Ą" title="Clown face" aria-label="Emoji: Clown face"> https://twitter.com/ricmoo/status/1245736131888582657">https://twitter.com/ricmoo/st...
Let& #39;s poke at it on mainnet...
We start by crafting and compiling version 1 of a simple contract called Wispy. The most important part is that the contract can self-destruct:
Next, instead of deploying the contract normally, we send a transaction to v0.rooted.eth with the bytecode of our contract. [txn fee: $0.25]
https://etherscan.io/tx/0xcd2230eb4caf474dd895557a6671eb455c219b01f9fa30e9873351369a2bf288">https://etherscan.io/tx/0xcd22...
https://etherscan.io/tx/0xcd2230eb4caf474dd895557a6671eb455c219b01f9fa30e9873351369a2bf288">https://etherscan.io/tx/0xcd22...
In the receipt of that transaction weâll see a log that has our new contract address. This will _always_ be the address of the contract created from _any_ bytecode that is deployed with this account to v0.rooted.eth. (We can also derive this address ahead of time if we need.)
We can now talk to our contract on mainnet and it will tell us that it is on version 1 and we are the owner:
Since we are the owner of this contract, we can send it the die() command and it will self-destruct: [txn fee: $0.01]
https://etherscan.io/tx/0x0fb8fe099da103b82bbf59ee32ffa8c091b9e952d07e1a8f5d21b36c5c3ca8dc">https://etherscan.io/tx/0x0fb8...
https://etherscan.io/tx/0x0fb8fe099da103b82bbf59ee32ffa8c091b9e952d07e1a8f5d21b36c5c3ca8dc">https://etherscan.io/tx/0x0fb8...
Now we update the code for our contract to add some new features, change the version to 2, and compile it to bytecode:
Like before, we send our bytecode to v0.rooted.eth instead of deploying it normally. [txn fee: $0.36]
https://etherscan.io/tx/0x477b5a0f9574e399e9d5b7a743300e888732ff5443018a66561e7eaadeba8128">https://etherscan.io/tx/0x477b...
https://etherscan.io/tx/0x477b5a0f9574e399e9d5b7a743300e888732ff5443018a66561e7eaadeba8128">https://etherscan.io/tx/0x477b...
Now when we ask the original contract address what version it is on now, we get 2!!! We can repeat this process of calling die() and adding more code to our contract and the contract address will always remain the same!
Hat tip to my dude @ricmoo! Here is the full build if you want to mess around with it:
#57579a1eee3b937c3d0b2b5a9a6d5c141ea0c3625bf953dafe55b4c28e1f32a3">https://eth.build/build #57579a1eee3b937c3d0b2b5a9a6d5c141ea0c3625bf953dafe55b4c28e1f32a3">https://eth.build/build...
#57579a1eee3b937c3d0b2b5a9a6d5c141ea0c3625bf953dafe55b4c28e1f32a3">https://eth.build/build #57579a1eee3b937c3d0b2b5a9a6d5c141ea0c3625bf953dafe55b4c28e1f32a3">https://eth.build/build...