V1 -> V2 Migration
npm install @0xsquid/sdk@^2.8.1
~ Widget V2 version to be released soon
- V1
- API
https://api.squidrouter.com/v1
- SDK
https://api.squidrouter.com
- V2
- API
https://v2.api.squidrouter.com/v2
- SDK
https://v2.api.squidrouter.com
- V1: Ethers V5
- V2: Ethers V5 or V6 up to v6.7.1 ##HIGHER VERSION NOT SUPPORTED YET##
npm i [email protected]
- The /route endpoint is now POST. /status is still a /GET request.
SDK
API
Our SDK handles this behind the scenes. No changes needed
const getRoute = async (params: any) => {
try {
const result = await axios.post(
"https://v2.api.squidrouter.com/v2/route",
params,
{
headers: {
"x-integrator-id": integratorId,
"Content-Type": "application/json",
},
}
);
const requestId = result.headers["x-request-id"];
return { data: result.data, requestId: requestId };
} catch (error) {
// Log the error response if it's available.
if (error.response) {
console.error("API error:", error.response.data);
}
console.error("Error with parameters:", params);
throw error;
}
};
- V1:
- import { ChainType, RouteResponse, SquidCallType } from "@0xsquid/sdk";
- V2: Slightly different import path
- import { ChainType, RouteResponse, SquidCallType } from "@0xsquid/sdk/dist/types";
Description
SDK
API
Click the tabs for example code
V1
const getSquidSDK = async () => {
const squid = new Squid({
baseUrl: "https://api.squidrouter.com",
});
await squid.init();
return squid;
};
V2 (set once in initial config)
const getSquidSDK = async () => {
const squid = new Squid({
baseUrl: "https://v2.api.squidrouter.com",
integratorId: "<your-integrator-id>
});
await squid.init();
return squid;
};
Add integrator-id to headers of every GET and POST request:
const getChains = async () => {
const result = await axios.get('https://v2.api.squidrouter.com/v2/chains', {
headers: {
'x-integrator-id': integratorId,
},
});
return result.data;
};
const getRoute = async (params: any) => {
try {
const result = await axios.post(
"https://v2.api.squidrouter.com/v2/route",
params,
{
headers: {
"x-integrator-id": integratorId,
"Content-Type": "application/json",
},
}
);
const requestId = result.headers["x-request-id"];
return { data: result.data, requestId: requestId };
} catch (error) {
// Log the error response if it's available.
if (error.response) {
console.error("API error:", error.response.data);
}
console.error("Error with parameters:", params);
throw error;
}
};
- Specifically check for
fromChain
andtoChain
- e.g. if chainId = 1, convert to chainId = "1"
- This is a request param in the
getRoute
function. Or on the/route
API endpoint.
- V2 introduces auto-slippage as default. Setting slippage manually is now optional
- V1
- // inside getRoute() paramsslippage: 1, // 1% slippage
- V2
- // inside getRoute() params// slippageConfig is requiredslippageConfig: {autoMode: 1, // 1 is "normal" slippage. Always set to 1},// optionally set slippage manually, this will override slippageConfigslippageConfig: {slippage: 1, // 1% slippageautoMode: 1, // ignored if manual slippage is set,},
Add
chainType: ChainType.EVM,
to every call object in your array of calls.{
chainType: ChainType.EVM, // only change in call structure for V2
callType: SquidCallType.FULL_TOKEN_BALANCE,
target: config.MANAPolygon,
value: "0",
callData: config.erc20ContractInterface.encodeFunctionData(
"transfer",
[userAddress, "0"]
),
payload: {
tokenAddress: config.MANAPolygon,
inputPos: 1,
},
estimatedGas: "50000",
}
The array of calls is now set under the
calls
key of the postHook object. There are some other params now. postHook = {
chainType: ChainType.EVM,
fundAmount: "0", // unused in postHook, only in preHook
fundToken: "0x", // unused in postHook, only in preHook
calls: yourArrayOfCalls
}
Last modified 19d ago