Working example!
You'll need to install Squid via npm first, then put in your Ropsten Ethereum RPC endpoint (from Infura for example) and your private key and you're good!
// test-squid-sdk.ts
import { Squid } from "@0xsquid/sdk";
import { ethers } from "ethers";
const privateKey = "";
const ethRpcEndPoint = "";
(async () => {
if (privateKey === "") throw new Error("Empty Private Key");
if (ethRpcEndPoint === "") throw new Error("RCP Endpoint missing");
const provider = new ethers.providers.JsonRpcProvider(ethRpcEndPoint);
const signer = new ethers.Wallet(privateKey, provider);
const config = {
baseUrl: "https://testnet.api.0xsquid.com/",
environment: "testnet" // this will be deprecated in coming days
};
const squid = new Squid(config); // config is optional in constructor
await squid.init();
console.log("squid initted");
const WETH = "0xc778417E063141139Fce010982780140Aa0cD5Ab";
const axlUSDCMoonbeam = "0xd1633f7fb3d716643125d6415d4177bc36b7186b";
const params = {
recipientAddress: signer.address,
sourceChainId: 3, // ropsten testnet
sourceTokenAddress: WETH,
sourceAmount: "50000000000000000", // 0.05 WETH
destinationChainId: 1287, // Moonbase Alpha testnet
destinationTokenAddress: axlUSDCMoonbeam,
slippage: 1 // unsupported in beta
};
const { route } = await squid.getRoute(params);
const tx = await squid.executeRoute({ signer, route });
const executedTx = await tx.wait();
console.log(executedTx);
})();
Copy link