-
Notifications
You must be signed in to change notification settings - Fork 7
/
sendTokensToOrigin.js
69 lines (53 loc) · 2.06 KB
/
sendTokensToOrigin.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { ethers } = require('ethers');
require('dotenv').config();
/*//////////////////////////////////////////////////////////////
GET CONSTANTS
//////////////////////////////////////////////////////////////*/
const destinationTokenAbi = require('../artifacts/contracts/DestinationToken.sol/DestinationToken.json');
const WALLET_PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY;
const BRIDGE_WALLET_PRIVATE_KEY = process.env.BRIDGE_WALLET_PRIVATE_KEY;
const DESTINATION_TOKEN_CONTRACT_ADDRESS =
process.env.DESTINATION_TOKEN_CONTRACT_ADDRESS;
const AMOY_PROVIDER_URL = process.env.AMOY_PROVIDER_URL;
if (!AMOY_PROVIDER_URL) {
console.error(new Error('Invalid provider url'));
process.exit(1);
}
if (!WALLET_PRIVATE_KEY) {
console.error(new Error('Invalid wallet key'));
process.exit(1);
}
if (!destinationTokenAbi.abi) {
throw new Error('ABI is undefined or not loaded correctly.');
}
/*//////////////////////////////////////////////////////////////
SETTINGS
//////////////////////////////////////////////////////////////*/
const rpcAmoyProvider = new ethers.JsonRpcProvider(AMOY_PROVIDER_URL);
const walletAmoy = new ethers.Wallet(WALLET_PRIVATE_KEY, rpcAmoyProvider);
const bridgeWallet = new ethers.Wallet(
BRIDGE_WALLET_PRIVATE_KEY,
rpcAmoyProvider,
);
const destinationToken = new ethers.Contract(
DESTINATION_TOKEN_CONTRACT_ADDRESS,
destinationTokenAbi.abi,
walletAmoy,
);
/*//////////////////////////////////////////////////////////////
TRANSACTION
//////////////////////////////////////////////////////////////*/
async function sendDestinationTokenToBridge() {
try {
const txResponse = await destinationToken.transfer(
bridgeWallet.address,
ethers.parseEther('1'),
);
console.log('Tx sent:', txResponse.hash);
const receipt = await txResponse.wait();
console.log('Tx confirmed:', receipt.blockNumber);
} catch (error) {
console.error('Tx error:', error);
}
}
sendDestinationTokenToBridge();