Skip to main content
POST
/
#particle_swap_getSwap
getSwap
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
}
'
import requests

url = "https://rpc.particle.network/evm-chain/#particle_swap_getSwap"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "particle_swap_getSwap",
    "params": ["0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8"],
    "chainId": 1
}
headers = {
    "Authorization": "Basic <encoded-value>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'particle_swap_getSwap',
    params: ['0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8'],
    chainId: 1
  })
};

fetch('https://rpc.particle.network/evm-chain/#particle_swap_getSwap', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://rpc.particle.network/evm-chain/#particle_swap_getSwap",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'jsonrpc' => '2.0',
    'id' => 1,
    'method' => 'particle_swap_getSwap',
    'params' => [
        '0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8'
    ],
    'chainId' => 1
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Basic <encoded-value>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://rpc.particle.network/evm-chain/#particle_swap_getSwap"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"particle_swap_getSwap\",\n  \"params\": [\n    \"0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8\"\n  ],\n  \"chainId\": 1\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Basic <encoded-value>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://rpc.particle.network/evm-chain/#particle_swap_getSwap")
  .header("Authorization", "Basic <encoded-value>")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"particle_swap_getSwap\",\n  \"params\": [\n    \"0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8\"\n  ],\n  \"chainId\": 1\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://rpc.particle.network/evm-chain/#particle_swap_getSwap")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"particle_swap_getSwap\",\n  \"params\": [\n    \"0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8\"\n  ],\n  \"chainId\": 1\n}"

response = http.request(request)
puts response.read_body
{
  "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
}

Understanding getSwap

  • getSwap 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.
    • Swap information object:
      • fromTokenAddress - string.
      • toTokenAddress - string.
      • amount - string.
      • slippage - integer.

Query example

JSON
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "particle_swap_getSwap",
  "params": [
    "0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8",
    {
      "fromTokenAddress": "0x111111111117dc0aa78b770fa6a738034120c302",
      "toTokenAddress": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
      "amount": "1000000000",
      "slippage": 1
    }
  ]
}

Authorizations

Authorization
string
header
required

Basic authentication header of the form Basic <encoded-value>, where <encoded-value> is the base64-encoded string username:password.

Body

application/json

Request to execute a token swap.

jsonrpc
string
default:2.0
required

Version of the JSON-RPC protocol, should be 2.0.

Example:

"2.0"

id
integer
default:1
required

The request identifier.

Example:

1

method
enum<string>
required

API method being called.

Available options:
particle_swap_getSwap
params
(string | object)[]
required

Parameters for executing a swap.

User address.

Example:

"0x369aa8a7a7BE683E1a46d9A056806B2B3FD778C8"

chainId
integer

The blockchain chain ID.

Example:

1

Response

200 - application/json

Successful response with swap transaction details.

jsonrpc
string
default:2.0
required

Version of the JSON-RPC protocol, should be 2.0.

Example:

"2.0"

id
integer
default:1
required

The request identifier.

Example:

1

result
object
required

Swap transaction details.

chainId
integer

The blockchain chain ID.

Example:

1