Swap via Smart Router
Step 1: Install Editor/IDE: Visual Studio Code (VS Code)
Official download: https://code.visualstudio.com
After downloading, simply extract and install
Step 2: Install Node: Use nvm
to Install and Switch Node.js
nvm
to Install and Switch Node.jsInstall 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
GitHub address: https://github.com/sun-protocol/SmartExchangeRouter
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
For more details, refer to Smart Routing Calculation Service
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
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.You can also refer to Smart Routing Swap Functions ---> 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