Learn how to use the getSwap JSON-RPC method.
curl --request POST \
--url 'https://rpc.particle.network/evm-chain/#particle_swap_getSwap' \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"id": 1,
"method": "particle_swap_getSwap",
"params": [
"0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8"
],
"chainId": 1
}
'{
"jsonrpc": "2.0",
"id": 1,
"result": {
"fromToken": {
"chainId": 1,
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"symbol": "DAI",
"name": "Dai Stablecoin",
"decimals": 18,
"logoURI": "https://static.particle.network/token-list/ethereum/0x6B175474E89094C44Da98b954EedeAC495271d0F.png"
},
"toToken": {
"chainId": 1,
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"symbol": "DAI",
"name": "Dai Stablecoin",
"decimals": 18,
"logoURI": "https://static.particle.network/token-list/ethereum/0x6B175474E89094C44Da98b954EedeAC495271d0F.png"
},
"toTokenAmount": "781970036",
"fromTokenAmount": "1000000000",
"tx": {
"to": "0x1111111254fb6c44bAC0beD2854e76F90643097d",
"data": "0x000",
"value": "0x0"
}
},
"chainId": 1
}getSwapgetSwap returns a detailed object containing swap information, a price quote, and a complete transaction object to have the user sign for swap execution. It takes:
address - string.fromTokenAddress - string.toTokenAddress - string.amount - string.slippage - integer.{
"id": 1,
"jsonrpc": "2.0",
"method": "particle_swap_getSwap",
"params": [
"0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8",
{
"fromTokenAddress": "0x111111111117dc0aa78b770fa6a738034120c302",
"toTokenAddress": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"amount": "1000000000",
"slippage": 1
}
]
}
Basic authentication header of the form Basic <encoded-value>, where <encoded-value> is the base64-encoded string username:password.
Request to execute a token swap.
Version of the JSON-RPC protocol, should be 2.0.
"2.0"
The request identifier.
1
API method being called.
particle_swap_getSwap Parameters for executing a swap.
User address.
"0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8"
The blockchain chain ID.
1
Successful response with swap transaction details.
Was this page helpful?
curl --request POST \
--url 'https://rpc.particle.network/evm-chain/#particle_swap_getSwap' \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"id": 1,
"method": "particle_swap_getSwap",
"params": [
"0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8"
],
"chainId": 1
}
'{
"jsonrpc": "2.0",
"id": 1,
"result": {
"fromToken": {
"chainId": 1,
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"symbol": "DAI",
"name": "Dai Stablecoin",
"decimals": 18,
"logoURI": "https://static.particle.network/token-list/ethereum/0x6B175474E89094C44Da98b954EedeAC495271d0F.png"
},
"toToken": {
"chainId": 1,
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"symbol": "DAI",
"name": "Dai Stablecoin",
"decimals": 18,
"logoURI": "https://static.particle.network/token-list/ethereum/0x6B175474E89094C44Da98b954EedeAC495271d0F.png"
},
"toTokenAmount": "781970036",
"fromTokenAmount": "1000000000",
"tx": {
"to": "0x1111111254fb6c44bAC0beD2854e76F90643097d",
"data": "0x000",
"value": "0x0"
}
},
"chainId": 1
}