-
Notifications
You must be signed in to change notification settings - Fork 0
/
alice.js
33 lines (28 loc) · 1.73 KB
/
alice.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
(async () => {
const ethers = require('ethers')
const zksync = require('zksync')
const utils = require('./utils')
const token = 'ETH'
const amountToDeposit = '0.05'
const amountToTransfer = '0.02'
const amountToWithdraw = '0.05'
const zkSyncProvider = await utils.getZkSyncProvider(zksync, process.env.NETWORK_NAME)
const ethersProvider = await utils.getEthereumProvider(ethers, process.env.NETWORK_NAME)
console.log('Creating a new Goerli wallet for Alice')
const aliceGoerliWallet = new ethers.Wallet(process.env.ALICE_PRIVATE_KEY, ethersProvider)
console.log(`Alice's Goerli address is: ${aliceGoerliWallet.address}`)
const aliceInitialGoerliBalance = await aliceGoerliWallet.getBalance()
console.log(`Alice's initial balance on Goerli is: ${ethers.utils.formatEther(aliceInitialGoerliBalance)}`)
console.log('Creating a zkSync wallet for Alice')
const aliceZkSyncWallet = await utils.initAccount(aliceGoerliWallet, zkSyncProvider, zksync)
console.log('Depositing')
await utils.depositToZkSync(aliceZkSyncWallet, token, amountToDeposit, ethers)
await utils.displayZkSyncBalance(aliceZkSyncWallet, ethers)
await utils.registerAccount(aliceZkSyncWallet)
console.log('Transferring')
const transferFee = await utils.getFee('Transfer', aliceGoerliWallet.address, token, zkSyncProvider, ethers)
await utils.transfer(aliceZkSyncWallet, process.env.BOB_ADDRESS, amountToTransfer, transferFee, token, zksync, ethers)
console.log('Withdrawing')
const withdrawalFee = await utils.getFee('Withdraw', aliceGoerliWallet.address, token, zkSyncProvider, ethers)
await utils.withdrawToEthereum(aliceZkSyncWallet, amountToWithdraw, withdrawalFee, token, zksync, ethers)
})()