Examples
Examples of using the REST API with Javascript
Example to get the estimated output from executing a bridge
async function estimateBridgeOutput(
fromChain,
toChain,
fromToken,
toToken,
amountFrom
) {
const query_string = `fromChain=${fromChain}&toChain=${toChain}&fromToken=${fromToken}&toToken=${toToken}&amountFrom=${amountFrom}`;
const response = await fetch(
`http://syn-api-dev.herokuapp.com/v1/estimate_bridge_output?${query_string}`
);
const response_json = await response.json();
return await response_json;
}
estimateBridgeOutput(
"AVALANCHE",
"BSC",
"USDC",
"USDC",
"100000000"
);
Example to generate an unsigned bridge transaction
async function generateUnsignedBridgeTxn(
fromChain,
toChain,
fromToken,
toToken,
amountFrom,
addressTo
) {
const query_string = `fromChain=${fromChain}&toChain=${toChain}&fromToken=${fromToken}&toToken=${toToken}&amountFrom=${amountFrom}&addressTo=${addressTo}`;
const response = await fetch(
`https://syn-api-dev.herokuapp.com/v1/generate_unsigned_bridge_txn?${query_string}`
);
const response_json = await response.json();
return await response_json;
}
generateUnsignedBridgeTxn(
"AVALANCHE",
"BSC",
"USDC",
"USDC",
"100000000",
"0x2D2c027E0d1A899a1965910Dd272bcaE1cD03c22"
);
Copy link