Skip to main content

Router API

ButterSwap Router API


Using Butter Router API, you can find the best route to exchange assets and make the exchange.

Step by step:

  1. Lookup addresses of tokens you want to swap, for example ‘0xxx’ , ‘0xxxx’ for DAI -> USDC
  2. Check for allowance of butter router contract to spend source asset (/approve/allowance)
  3. If necessary, give approval for butter router to spend source token (/approve/transaction)
  4. Monitor the best exchange route using (/swap/calculateTrade)

chainIds

NameChainId
ETHEREUMETH1
BINANCE_SMART_CHAINBSC56
POLYGONPOLYGON137
AVALANCHEAVALANCHE43114
MOONRIVERMOONRIVER1285
FANTOMFANTOM250
HARMONYHARMONY1666600000
ARBITRUMARBITRUM42161
AURORAAURORA1313161554
TELOSTELOS40
OPTIMISMOPTIMISM10
CRONOSCRONOS25
OKE_X_CHAINOKX66
GNOSISGNOSIS100
FUSEFUSE122
MOONBEAMMOONBEAM1284
CELOCELO42220
BOBABOBA288
BOBA_BSCBOBA_BSC56288
BOBA_AVALANCHEBOBA_AVALANCHE43288
ASTAR_EVMASTAR_EVM592
ETHEREUM_POWETHW10001
KAVAKAVA2222
BITGERTBITGERT32520
OASISOASIS42262
METISMETIS1088
DFKDEFIKINGDOMS53935
KLAYTNKLAYTN8217
VELASVELAS106
SYSCOINSYSCOIN57
ETHEREUM_CLASSICETHEREUM_CLASSIC61
FLAREFLARE14
IOTEXIOTEX4689
THETATHETA361
BITCOIN_CASHBITCOIN_CASH10000
ZK_SYNCZK_SYNC324

baseUrl = https://router-api.butterswap.io

1.1 Address of the butter router that must be trusted to spend funds for the exchange:

baseUrl/{chainId}/approve/spender

//No parameters

//Responses
{
errno:0
message: 'success'
data: {
address: "0x0154BDb55477a74c9421cd52Cf9cbE14Db4E5805"
}

}
1.2 Generate data for calling the contract in order to allow the butter router to spend funds:

baseUrl/{chainId}/approve/transaction

Parameters

NameDescription
tokenAddress * string (query)Token address you want to exchange Example : 0x4988a896b1227218e4a686fde5eabdcabd91571f
amount string (query)The number of tokens that the butter router is allowed to spend.If not specified, it will be allowed to spend an infinite amount of tokens. Example : 100000000000
//Responses
{
errno:0
message: 'success'
data: {
data: "0x095ea7b3000000000000000000000000bdc0aafb30913222334cb8008eebdf59089269bf00000000000000000000000000000000000000000000000000000000000f4240"
gasPrice: "15000000000"
to: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"
value: "0"
}

}
1.3 Get the number of tokens that the butter router is allowed to spend:

baseUrl/{chainId}/approve/allowance

Parameters

NameDescription
tokenAddress * string (query)Token address you want to exchange Example : 0xc7198437980c041c805a1edcba50c1ce5db95118
walletAddress * string (query)Wallet address for which you want to check
//Responses

{
errno:0
message: 'success'
data: {
allowance: "0"
}

}
1.4 Generate data for calling the butter router for exchange:

baseUrl/{chainId}/swap/calculateTrade

Parameters

NameDescription
fromTokenAddress * string(query)0x0000000000000000000000000000000000000000
toTokenAddress * string (query)0xc7198437980c041c805a1edcba50c1ce5db95118
amount * string (query)10000000000000000
fromAddress * string (query)The address that calls the butter contract
feeType * string (query)pay fees with: stableToken: 0; fromToken: 1

{
"errno": 0,
"message": "success",
"data": {
"from": {
"blockchain": "POLYGON",
"address": "0x0000000000000000000000000000000000000000",
"name": "Matic Network",
"symbol": "MATIC",
"decimals": 18,
"_price": "0.882938",
"_weiAmount": "997000000000000000"
},
"to": {
"blockchain": "POLYGON",
"address": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
"name": "USD Coin (PoS)",
"symbol": "USDC",
"decimals": 6,
"_price": "1",
"_weiAmount": "879690"
},
"path": [
{
"blockchain": "POLYGON",
"address": "0x0000000000000000000000000000000000000000",
"name": "Matic Network",
"symbol": "MATIC",
"decimals": 18,
"_price": "0.882938",
"_weiAmount": "997000000000000000"
},
{
"blockchain": "POLYGON",
"address": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
"name": "USD Coin (PoS)",
"symbol": "USDC",
"decimals": 6,
"_price": "1"
}
],
"tx": {
"to": "0xDC836538aCec08300d548A89889fEdf3BcAbD218",
"data": "0x67337e2200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000644a66b76e740d98f0d23c3ae942163bb43078c10000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000104414bf3890000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf12700000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa8417400000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000644a66b76e740d98f0d23c3ae942163bb43078c100000000000000000000000000000000000000000000000000000000646c6ecd0000000000000000000000000000000000000000000000000dd60e37b910800000000000000000000000000000000000000000000000000000000000000d279000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"value": "1000000000000000000",
"gasPrice": "137810739340"
},
"type": "UNI_SWAP_V3",
"toTokenAmount": "879690"
}
}
1.5 Generate data for calling the butter router for cross chain exchange:

baseUrl/{chainId}/swap/calculateCrossTrade

Parameters

NameDescription
fromTokenAddress * string(query)0xc2132D05D31c914a87C6611C10748AEb04B58e8F
toTokenAddress * string (query)0x524bC91Dc82d6b90EF29F76A3ECAaBAffFD490Bc
amount * string (query)20000000
fromAddress * string (query)The address that calls the butter contract
toChainId * int (query)The chainId to cross chain
feeType * string (query)pay fees with: stableToken: 0; fromToken: 1
{
"errno": 0,
"message": "success",
"data": {
"from": {
"blockchain": "POLYGON",
"address": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
"name": "(PoS) Tether USD",
"symbol": "USDT",
"decimals": 6,
"_price": "0.999877",
"_weiAmount": "19940000"
},
"to": {
"blockchain": "BSC",
"address": "0x524bC91Dc82d6b90EF29F76A3ECAaBAffFD490Bc",
"name": "Tether USD",
"symbol": "USDT",
"decimals": 6,
"_price": "0.998025",
"_weiAmount": "19928036"
},
"path": {},
"tx": {
"to": "0x0154BDb55477a74c9421cd52Cf9cbE14Db4E5805",
"data": "0x67337e22000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f0000000000000000000000000000000000000000000000000000000001312d00000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000068000000000000000000000000000000000000000000000000000000000000006a000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003335733c454805df6a77f825f266e136fb4a33330000000000000000000000003335733c454805df6a77f825f266e136fb4a3333000000000000000000000000644a66b76e740d98f0d23c3ae942163bb43078c1000000000000000000000000524bc91dc82d6b90ef29f76a3ecaabafffd490bc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000464e1fcde8e000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000013042a0000000000000000000000000000000000000000000000000000000000000034482361d3a00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000200fc704da9ea3dd5831be92e15fa6f6def1718ba05adec90f4183f9422afc366fa00000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cf6cc2390d1ed49a14de5415f8238cec9b73ae48000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f000000000000000000000000524bc91dc82d6b90ef29f76a3ecaabafffd490bc000000000000000000000000644a66b76e740d98f0d23c3ae942163bb43078c1000000000000000000000000644a66b76e740d98f0d23c3ae942163bb43078c100000000000000000000000000000000000000000000000000000000013042a0000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f6e61746976653a73746172676174650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000013013e400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c72a61052215956000000000000000000000000644a66b76e740d98f0d23c3ae942163bb43078c100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000014644a66b76e740d98f0d23c3ae942163bb43078c10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"value": "3233339498217395030",
"gasPrice": "163718836992"
},
"bridgeType": "stargate",
"onChainSubtype":{"from":"ONE_INCH","to":"ZRX"},
"toTokenAmount": "19928036"
}
}