Contract Calls

Contract calls allow developers to execute complex transactions on the same chain or across different blockchains as one single transaction. This enables deposits into staking, lending or liquidity protocols from any token as a single transaction which otherwise would have taken anywhere between 2-10 transactions.

Swing seamlessly connects to bridges, DEXes and protocols to execute complex on-chain transactions.

Our contracts were audited on 31 May 2023, by Peckshield Audit. view audit report Monetize your integration by collecting partner fees up to 10% of the transaction volume. Learn More

1. Cross-Chain Contract Calls

Swing passes tokens and contract-call data through a bridge to bridge assets and executes the contract call(s) on the destination blockchain. This allows developers to perform cross-chain transactions in a single transaction on the source blockchain, without the need to switch RPC or sign another transaction on the destination blockchain.

The bridges will pay the gas fee for the transactions on the destination chain. For example, Stargate requires native tokens to be provided to cover the destination-chain gas cost for sending the tokens to the user. Swing estimates the destination transaction fee and returns it in the quote response.

For example, in a normal any-to-any cross-chain swap, converting MATIC on Polygon to ETH on Ethereum and staking into Lido staking protocol requires several steps. With Swing, you can perform all four steps in a single transaction on Polygon by passing the destination swap contract-call data through a bridge to execute the final swap and staking for the user and then send the staked tokens to the user.

2. Single-Chain Contract Calls

Swing API passes contract-call data to Swing Contract to execute multiple transactions as one single transaction on the same chain. This allows developers to build an experience that allows users to send any token to deposit tokens into a protocol and more.

For example, a user sends USDT on Ethereum to stake ETH into the Lido protocol. Swing swaps USDT to ETH with Paraswap, deposits ETH into Lido protocol and sends stETH to the user's wallet - all in one single transaction.

The full API reference for our /quote, /approve, /allowance and /send endpoints can be found in the API reference section.

In this section, we will discuss the process of executing a contract-call transaction which involves exchanging assets, sending them across blockchain networks and performing a deposit into a protocol. Accomplishing a successful transaction requires making calls to our endpoints to move the transaction through its various stages.

Implementation Stages

  1. Get projectId - Create a project to send a unique projectId to the API
  2. Get quote - Retrieving a valid quote from a contract-call-supported routes
  3. Get approval - Getting approval for native token transfers/swaps
  4. Send transaction - Initiating transaction given the prior quote on a specific route
  5. Get transaction status - Waiting for the transaction to complete by polling for transaction status
  6. Transaction Complete!