/
1-withdraw.js
50 lines (37 loc) · 1.63 KB
/
1-withdraw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { BigNumber, providers, Wallet } = require('ethers')
const { ethers } = require('hardhat')
const { expect } = require ('chai')
const { getL2Network, Erc20Bridger, L1ToL2MessageStatus } = require("@arbitrum/sdk")
require('dotenv').config()
let rootTokenAddress = "0xA163301ED403aBbf637A9119593c07eec212fD0B";
const walletPrivateKey = process.env.PRIVATE_KEY
const l1Provider = new providers.JsonRpcProvider(process.env.RINKEBY_URL)
const l1Wallet = new Wallet(walletPrivateKey, l1Provider)
const l2Provider = new providers.JsonRpcProvider(process.env.ARBITRUM_TESTNET_URL)
const l2Wallet = new Wallet(walletPrivateKey, l2Provider)
const main = async () => {
const tokenWithdrawAmount = hre.ethers.utils.parseEther('1000.0')
const l2Network = await getL2Network(l2Provider)
const erc20Bridge = new Erc20Bridger(l2Network)
logWithTime("Initiating withdrawal from L2")
const withdrawTx = await erc20Bridge.withdraw({
amount:tokenWithdrawAmount,
erc20l1Address: rootTokenAddress,
l2Signer: l2Wallet
})
logWithTime(`withdrawTx hash: ${withdrawTx.hash}`)
//0x9e9031e606d4d999c4dfd02fd4ef68e1789cd4ac8dbd41955787122b7bdf5c77
//0xf989f381b40d99014384a5f8a4f08cf324b6969a3e0ad4d2bfa2b8857897aca0
const withdrawRec = await withdrawTx.wait()
logWithTime(`withdrawRec hash: ${withdrawRec.transactionHash}`)
logWithTime("Finished initiating withdrawal from L2")
}
function logWithTime(message){
console.log(`${new Date().toTimeString()} - ${message}`);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error)
process.exit(1)
})