Rubic Documents
  • RUBIC
    • Overview
    • Rubic's Ecosystem
    • Security
    • Tokenomics
    • Roadmap
    • Rubic Discord Roles
    • “Swap to Earn” Program on Rubic
    • MEV-bot Protection
    • B2B Cross-Chain Toolkit
      • Use Cases
      • Why Rubic?
    • Refund Guidelines for Stuck Transactions
  • ⚒️Integrate SDK
    • SDK Overview
    • SDK Architecture
    • SDK Advantages
    • SDK Integration
    • 1️⃣Install SDK
    • 2️⃣Set up SDK
    • 3️⃣Trade calculation
    • 4️⃣Swap Execution
    • 📜Advanced documentation
    • Migration from V2 to V3
    • Contact Us
  • Integrate Widget
    • Widget Overview
    • Instruction
    • White Label Widget Integration Instruction
    • Partners
    • Listing of tokens
  • Rubic API
    • 🔐Tokens API
    • Referrer And Rate Limits
    • Rubic API
      • Supported chains
      • Supported providers
      • Request Quote
      • Request Data
      • Get Cross-Chain Status
      • Integration example
        • Swaps from EVM
        • Swaps from Solana
        • Swaps from TON
        • Swaps from Tron
        • Swaps from Bitcoin
        • Swaps VIA deposit
      • Swagger
      • Models
        • OnChainTradeType
        • CrossChainTradeType
        • FeesDto
        • RoutingDto
        • TransactionDto
        • ErrorDto
      • Errors
    • Monetization And Fees
  • FAQ
    • What is Rubic?
    • How to start using Rubic?
    • Who can use our service?
    • Is KYC required?
    • What are the minimum and maximum trade sizes?
    • Should I list my token before using your service?
    • How to create a Swap?
    • How long does it take to complete a transaction?
    • How is the privacy and security of the transaction ensured?
    • How does Rubic unite different DEX platforms?
    • Why does Rubic offer a choice between different providers?
    • How do I add the BNB Smart Chain and Polygon networks to MetaMask?
    • What should I do when I see the message: “Trading on Uniswap is not available?”
    • What should I do if Uniswap doesn’t display any rates?
    • How can we integrate the Rubic Relay widget?
    • How do we get listed on Rubic?
    • How to Complete swaps to/from TON network using Rubic
  • Contacts
    • Community
    • PR Marketing
    • Business Development
    • Support
    • Influencers Collaboration Requests
  • Legal Documentation
    • Privacy Policy
    • Terms of Use
    • Third-Party Software
  • Audits
    • MixBytes Audit
  • Pitch Deck
Powered by GitBook
On this page

Was this helpful?

  1. Integrate SDK

Swap Execution

Before swap, you should calculate a trade object

Swap for both On-Chain and Cross-Chain trade are pretty similar and very easy to use. You just have to call swap method in trade object (instantTrade or crossChain).

On-Chain trade example

const trades = await sdk.onChainManager.calculateTrade(...);
const bestTrade = trades[0] instanceof OnChainTrade && trades[0];
const receipt = await bestTrade.swap();

Cross-Chain trade example

const trade = await sdk.crossChain.calculateTrade(tradeParams);
const bestTrade = trades[0].trade.swap();
const transactionHash = await bestTrade.swap();

After swap execution you will get the transaction receipt or hash in case of cross-chain swap.

Well done!

Swap options

Swap method takes optional params with options:

interface SwapOptions {    
  /**
   * Callback to be called, when user confirm swap transaction.
   * @param hash Transaction hash.
   */
  onConfirm?: (hash: string) => void;

  /**
   * Callback to be called, when user confirm approve transaction.
   * @param hash Transaction hash.
   */
  onApprove?: (hash: string | null) => void;
  
  /**
   * Tokens receiver address.
   */
  receiverAddress?: string;

  /**
   * Transaction gas price options.
   */
  gasPriceOptions?: EIP1559Gas | SingleGasPrice;

  /**
   * Approve transaction gas limit.
   * Will be used for approve transaction, if it is called before swap.
   */
  approveGasLimit?: string;
  
  /**
   * Approve tron-transaction fee limit.
   * Will be used for approve transaction, if it is called before swap.
   */
  approveFeeLimit?: number;
}
 

With these parameters, you can specify your gas data or actions which will be executed right after transaction signing.

PreviousTrade calculationNextAdvanced documentation

Last updated 11 months ago

Was this helpful?

⚒️
4️⃣