SUN.io Docs
SUN.ioSunPump
  • SUN.io Overview
    • Get Started(TRON)
      • Create a Wallet
      • TRON Network Token Standards
      • Connect Your Wallet to SUN.io
    • Risks
    • Whitepaper
    • Terms of Service
    • Privacy Policy
    • Announcement
  • GET START
    • Exchange
      • Token Swaps
        • How to authorize a token?
        • How to exchange tokens?
        • How to check my recent transaction history?
        • How to view 24h price trend of a pair ?
      • Stablecoin Pool
        • Stablecoin pool overview
        • How to swap stablecoins?
        • How to provide liquidity for a stablecoin pool?
        • How to withdraw liquidity from a stablecoin pool?
        • How to check the liquidity you have provided?
      • Smart Router
      • Trading Fee
        • Claim Fee Rewards
      • Liquidity Pool
        • How to create a trading pair?
        • How to add liquidity?
        • How to remove liquidity?
        • How to calculate the ratio of tokens to be added to/removed from the pool?
        • How to record a new token?
        • What's the initial price for creating a fund pool?
      • Token Lists
    • Mining Pool
      • Mining Rules of SUN.io
      • How to participate in liquidity mining?
      • How to earn liquidity mining rewards?
      • How to exit liquidity mining?
      • How to calculate the boost rate of LP mining pool?
      • How to lock SUN?
      • How to vote?
      • How to reset votes?
      • Intelligent Boost Mining Pool
        • How to participate in Fixed Staking?
        • How to stake more assets in Fixed Staking?
        • How to extend duration in Fixed Staking?
        • How to make an early withdrawal in Fixed Staking?
        • How to claim rewards in Fixed Staking?
      • Farm
      • Ended Farming Pools
    • SunPump
      • 🌞 How to Participate?
      • 🚀 How to Launch?
      • 💡 Token Details
      • 👤 Personal Profile
      • 🏦 Service Fees
      • How to Use DLive Streaming on SunPump
    • SunPump Referral
      • How to Join
      • Rules
      • FAQ
    • PSM
      • How to swap between USDD and other stablecoins at 1:1 ratio in PSM?
    • Tokenomics
      • SUN Tokenomics
        • Buyback & Burning of the SUN Token
      • veSUN
      • Airdrop
  • GOVERNANCE
    • SUN DAO Governance
    • Participating Governance
      • Proposal
        • SUN DAO Forum
        • How to get more votes?
        • Create Proposal
        • How to vote on the SUN DAO?
        • SUN DAO proposal
      • Governance Rights
        • Weight
        • veSUN
  • DEVELOPERS
    • Swap
      • StableSwap Overview
      • SunSwap Overview
      • SunSwap V3 Overview
      • Smart Router
        • Contract
        • Calculation Service
        • Exchange Functions
        • Detailed Development Steps
    • Mining
      • Smart Mining V1
      • Smart Mining V2
      • Governance Mining
    • Sunpump
      • Sunpump Contracts
    • Github
    • Contracts and ABIs
  • FAQ
    • How to use Sun.io in TronLink Mobile?
    • How is price determined?
    • What tokens are supported for swap?
    • Why does my exchange fail?
    • Detailed Explanation of SUN.io Platform Energy Subsidies
Powered by GitBook
On this page
  • Step 1: Install Editor/IDE: Visual Studio Code (VS Code)
  • Step 2: Install Node: Use nvm to Install and Switch Node.js
  • Step 3: Clone Project Code Locally
  • Step 4: Install All Required Components
  • Step 5: Configure Private Key
  • Step 6: Obtain Optimal Exchange Path Based on Smart Routing Calculation Service Interface
  • Step 7: Build Transaction
  • Step 8: Complete Code
  • Step 9: Execute Transaction
  1. DEVELOPERS
  2. Swap
  3. Smart Router

Detailed Development Steps

PreviousExchange FunctionsNextMining

Last updated 1 day ago

Step 1: Install Editor/IDE: Visual Studio Code (VS Code)

  • Official download:

  • After downloading, simply extract and install

Step 2: Install Node: Use nvm to Install and Switch Node.js

  • Install NVM

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  • Load NVM:

source ~/.zshrc     # If you use zsh
# Or:
source ~/.bash_profile
  • Install the latest version of Node.js:

nvm install 22
  • Switch to the newly installed version:

nvm use 22
  • Set the new version as default:

nvm alias default 22
  • Verify versions:

node -v
npm -v

Step 3: Clone Project Code Locally

Step 4: Install All Required Components

  • Open the project file with VS Code

  • Enter the following in the bottom command line for automatic installation

npm install

Step 5: Configure Private Key

export PRIVATE_KEY_NILE=Your private key
  • After configuration, enter env to check if the configuration is successful

Step 6: Obtain Optimal Exchange Path Based on Smart Routing Calculation Service Interface

  • After obtaining the optimal 3 exchange paths, you can build transactions based on the optimal path

Step 7: Build Transaction

  • Users can call the swapExactInput method of the smart contract to trigger transactions. The Smart Router will process the transaction data internally and complete the transaction.

Step 8: Complete Code

  • For complete code, please refer to the request.mjs file in the project. You can replace the function parameters at the bottom according to your needs.

Step 9: Execute Transaction

node scripts/request.mjs

GitHub address:

For more details, refer to

For more details, refer to

You can also refer to

After the transaction is successfully executed, it returns the transaction hash. You can further view the detailed information of the transaction on using the hash.

https://code.visualstudio.com
https://github.com/sun-protocol/SmartExchangeRouter
Smart Routing Calculation Service
Smart Routing Exchange Functions
Smart Routing Exchange Functions ---> Complete Code
tronscan