-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (64 loc) · 1.56 KB
/
index.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
70
const ethers = require("ethers"); // assuming commonjs
require("dotenv").config();
const ABI = [
{
inputs: [
{
internalType: "address",
name: "token",
type: "address",
},
{
internalType: "address",
name: "to",
type: "address",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
{
internalType: "uint256",
name: "toChainID",
type: "uint256",
},
],
name: "anySwapOutUnderlying",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];
const env = {
KEY: process.env.KEY,
};
const config = {
routerAddress: "0x3f9520d640085b5d2be2b294d6f12786286a2a14",
toAddress: "0xEFcc454b4b2F4D7F89E8D9aB9Cb2d45630a3EFf0",
amount: ethers.utils.parseEther("0.15"), // min swap is 0.1
destChainID: 18,
homeTokenAddress: "0xed24fc36d5ee211ea25a80239fb8c4cfd80f12ee",
homeRPC: "https://data-seed-prebsc-1-s1.binance.org:8545",
};
async function main() {
const provider = new ethers.providers.JsonRpcProvider(config.homeRPC);
const wallet = new ethers.Wallet(env.KEY, provider);
const router = new ethers.Contract(config.routerAddress, ABI, wallet);
await router
.anySwapOutUnderlying(
config.homeTokenAddress,
config.toAddress,
config.amount,
config.destChainID
)
.then((tx) => {
console.log("Transaction hash: " + tx.hash);
});
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});