Skip to content

Instantly share code, notes, and snippets.

@asselstine
Created December 7, 2022 01:10
Show Gist options
  • Save asselstine/37429e42fcb9807dbfcde9a6376be5d4 to your computer and use it in GitHub Desktop.
Save asselstine/37429e42fcb9807dbfcde9a6376be5d4 to your computer and use it in GitHub Desktop.
Generate Withdrawal Proof for Polygon
/*
You may need to manually withdraw from the Polygon blockchain.
Once you've run the withdraw transaction on Polygon, you'll need to provide a burn proof on Ethereum.
Use the script below to generate the proof, then go to the WithdrawToWrapperRoot contract on Etherscan:
https://etherscan.io/address/0xb67a8438e15918de8f42aab84eb3950f2588a534
paste in the burn proof and enter '1' for the offset
*/
// You'll need the following packages
const matic = require("@maticnetwork/maticjs")
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3")
const { ExitUtil, Web3SideChainClient, RootChain, ABIManager } = matic
matic.use(Web3ClientPlugin)
const config = {
network: 'mainnet',
version: 'v1',
parent: {
provider: ETHEREUM_RPC_URL
},
child: {
provider: POLYGON_RPC_URL
},
}
// Don't change this
const TRANSFER_EVENT_SIG = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
// Enter the Polygon tx hash of the withdrawal
const BURN_TX_HASH = '?'
// if there were multiple token transfers in the withdrawal, you can enter the index here
const INDEX_OF_TOKEN_TRANSFER = '?'
const client = new Web3SideChainClient()
client.init(config).then(() => {
const rootChain = new RootChain(client, '0x86E4Dc95c7FBdBf52e33D563BbDB00823894C287')
const exit = new ExitUtil(client, rootChain)
return exit.buildPayloadForExit(BURN_TX_HASH, TRANSFER_EVENT_SIG, false, INDEX_OF_TOKEN_TRANSFER).then(console.log)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment