-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
54 lines (42 loc) · 1.35 KB
/
index.ts
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
import { Squid } from "@0xsquid/sdk";
import { ethers } from "ethers";
import dotenv from "dotenv";
dotenv.config();
const privateKey = process.env.PK!;
if (!privateKey)
throw new Error("No private key provided, pls include in .env file");
(async () => {
// instantiate the SDK
const squid = new Squid({
baseUrl: "https://squid-2gwsw7ij1-0xsquid.vercel.app", // for testnet use "https://testnet.api.0xsquid.com"
});
// init the SDK
await squid.init();
console.log("Squid inited");
// use the RPC provider of the "from" chain
const chainId = 43113; //avalanche
const provider = ethers.getDefaultProvider(
squid.chains.find((c) => c.chainId === chainId)!.rpc
);
const signer = new ethers.Wallet(privateKey, provider);
const params = {
fromChain: chainId,
fromToken: squid.tokens.find(
(t) => t.symbol === "AVAX" && t.chainId === chainId
).address,
fromAmount: ethers.utils.parseUnits("0.1", "18").toString(),
toChain: "axelar-testnet-lisbon-3",
toToken: "uosmo",
toAddress: "axelar1zqnudqmjrgh9m3ec9yztkrn4ttx7ys64d2ak9f",
slippage: 3.0,
enableForecall: false,
quoteOnly: false,
};
const { route } = await squid.getRoute(params);
const tx = await squid.executeRoute({
signer,
route,
});
const txReceipt = await tx.wait();
console.log(txReceipt.transactionHash);
})();