Swap via Smart Router

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

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

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.

  • For more details, refer to Smart Routing Swap Functions

Step 8: Complete Code

Step 9: Execute Transaction

node scripts/request.mjs
  • After the transaction is successfully executed, it returns the transaction hash. You can further view the detailed information of the transaction on tronscan using the hash.

Last updated