Examples

Examples of using the REST API with Javascript
Example 1:
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(
`https://synapse-rest-api-v2.herokuapp.com/estimate_bridge_output?${query_string}`
);
const response_json = await response.json();
return await response_json;
}
estimateBridgeOutput(
"AVALANCHE",
"BSC",
"USDC",
"USDC",
"100000000"
);
Example 2:
Generate an unsigned bridge transaction
async function generateUnsignedBridgeTxn(
fromChain,
toChain,
fromToken,
toToken,
amount,
destAddress
) {
const query_string = `fromChain=${fromChain}&toChain=${toChain}&fromToken=${fromToken}&toToken=${toToken}&amount=${amountFrom}&destAddress=${addressTo}`;
const response = await fetch(
`https://synapse-rest-api-v2.herokuapp.com/generate_unsigned_bridge_txn?${query_string}`
);
const response_json = await response.json();
return await response_json;
}
generateUnsignedBridgeTxn(
"AVALANCHE",
"BSC",
"USDC",
"USDC",
"100000000",
"0x2D2c027E0d1A899a1965910Dd272bcaE1cD03c22"
);
Example 3:
A cURL request to get information about a swap transaction.
curl --request GET \
--url 'https://synapse-rest-api-v2.herokuapp.com/swap?chain=1&fromToken=USDC&toToken=DAI&amount=100'