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/bridge?${query_string}`
  );
  

  const response_json = await response.json();
  return await response_json;
}

estimateBridgeOutput(
  1,     // Ethereum Chain ID
  42161, //Arbitrum Chain ID
  "USDC", 
  "USDC", 
  "1000"
);

Example 2:

Generate an unsigned bridge transaction

async function generateUnsignedBridgeTxn(
  fromChain,
  toChain,
  fromToken,
  toToken,
  amountFrom,
  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/bridgeTxInfo?${query_string}`
  );
  const response_json = await response.json();
  return await response_json;
}

generateUnsignedBridgeTxn(
   1,     // Ethereum Chain ID
  42161, //Arbitrum Chain ID
  "USDC", 
  "USDC", 
  "1000"
  "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'

Last updated