Swing Points Program is Live 🚀 Learn More →

Gathering Transaction Info

The first step to executing a transaction is gathering the source chain and destination chain information, as well as the swap amount, sender and recipient wallet addresses, and the project's ID. Swing provides endpoints for fetching a list of chains and tokens that are available on the Swing ecosystem.

const transferParams = {
  // source chain info
  fromChain: 'ethereum',
  fromTokenAddress: '0x0000000000000000000000000000000000000000',
  fromUserAddress: '0x018c15DA1239B84b08283799B89045CD476BBbBb',
  tokenSymbol: 'ETH',
 
  // destination chain info
  toTokenAddress: '0x0000000000000000000000000000000000000000',
  toChain: 'polygon',
  tokenAmount: 100000000000,
  toTokenSymbol: 'MATIC',
  toUserAddress: '0x018c15DA1239B84b08283799B89045CD476BBbBb',
 
  // project config
  projectId: 'replug',
};

Get all chains and tokens

We are continuously expanding our ecosystem by incorporating new blockchain networks and tokens to allow for a greater number of cross-chain token transfers and swaps.

To get a list of all chains and all tokens that are currently supported, the /chains and /tokens endpoint can be queried.

const chainsResponse = await fetch('https://platform.swing.xyz/api/v1/chains');
const chains = await chainsResponse.json();
 
const tokensResponse = await fetch('https://platform.swing.xyz/api/v1/tokens');
const tokens = await tokensResponse.json();

Get enabled chains and tokens for a project

To get a list of all chains and all tokens that are currently enabled by your project's rules configuration, the /projects/{projectId}/chains and /projects/{projectId}/tokens endpoint can be queried.

const PROJECT_ID = 'your-project-id';
 
const projectChainsResponse = await fetch(
  `https://platform.swing.xyz/api/v1/projects/${PROJECT_ID}/chains`,
);
const chains = await projectChainsResponse.json();
 
const projectTokensResponse = await fetch(
  `https://platform.swing.xyz/api/v1/projects/${PROJECT_ID}/tokens`,
);
const tokens = await projectTokensResponse.json();