Giter Club home page Giter Club logo

recovereth's Introduction

RecoverEth

Recovers eth sent to a contract on the wrong chain

Background

I was playing with a prototype and sent 1.2 Eth to an address on Mainnet instead of 1.2 Polygon to a contract on Polygon.

Luckily, there was no activity on the corresponding mainnet address, so it was possible to recover the funds Unluckily, the contract was written on nonce 52, so it would require 51 empty transactions on the main net chain before the recovery contract can be written to the corresponding address.

To Use:

  1. Use Etherscan (or equivalent) to work out the nonce of the contract deployment on the chain you wanted to send the funds to, eg 52.
  2. Set the TARGET_NONCE value in class RecoverEth to this value.
  3. Copy/Paste the private key that deployed the contract into the PRIVATE_KEY value eg PRIVATE_KEY = "123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234";
  4. Set the DEPLOYMENT_CHAIN to the chain that you accidentally sent the funds to, eg DEPLOYMENT_CHAIN = MAINNET_ID. You can also just use the chain number directly
  5. Open the recovereth.sol contract and change the destAddr payment address to your address.
  6. Compile using solcjs (or whichever Solidity compiler you like) >solcjs recovereth.sol --base-path . --optimize --bin
  7. Copy the hex in the generated .bin file to the PAYOUT_CONTRACT eg PAYOUT_CONTRACT = "0x608060...";
  8. Ensure you have a node setup for the chain you're using in private Web3j getWeb3j() {
  9. Double check all the settings! You only have one go at this. You may want to do a test-run on a testnet using the same values.
  10. Use

./gradlew run

Watch the transactions appear until you see the final "Send Ctor transaction" text. The program will wait for you to manually terminate it.

Finally check Etherscan to make sure everything worked. Your funds should be back in your account.

recovereth's People

Contributors

jamessmartcell avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.