Transactions
Create Swap Transaction
Construct an unsigned swap transaction from a previously obtained quote route.
POST
/
api
/
defi
/
v1
/
transactions
/
swap
/
build
Create Swap Transaction
curl --request POST \
--url https://edge.p2p.org/api/defi/v1/transactions/swap/build \
--header 'Content-Type: application/json' \
--header 'X-Client-Hash: <api-key>' \
--data '
{
"inChain": "ethereum",
"wallet": "<string>",
"outTokenSymbol": "USR",
"amount": "1000000",
"route": {},
"slippageBps": 1000,
"provider": "kyberswap"
}
'import requests
url = "https://edge.p2p.org/api/defi/v1/transactions/swap/build"
payload = {
"inChain": "ethereum",
"wallet": "<string>",
"outTokenSymbol": "USR",
"amount": "1000000",
"route": {},
"slippageBps": 1000,
"provider": "kyberswap"
}
headers = {
"X-Client-Hash": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Client-Hash': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
inChain: 'ethereum',
wallet: '<string>',
outTokenSymbol: 'USR',
amount: '1000000',
route: {},
slippageBps: 1000,
provider: 'kyberswap'
})
};
fetch('https://edge.p2p.org/api/defi/v1/transactions/swap/build', 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://edge.p2p.org/api/defi/v1/transactions/swap/build",
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([
'inChain' => 'ethereum',
'wallet' => '<string>',
'outTokenSymbol' => 'USR',
'amount' => '1000000',
'route' => [
],
'slippageBps' => 1000,
'provider' => 'kyberswap'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Client-Hash: <api-key>"
],
]);
$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://edge.p2p.org/api/defi/v1/transactions/swap/build"
payload := strings.NewReader("{\n \"inChain\": \"ethereum\",\n \"wallet\": \"<string>\",\n \"outTokenSymbol\": \"USR\",\n \"amount\": \"1000000\",\n \"route\": {},\n \"slippageBps\": 1000,\n \"provider\": \"kyberswap\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Client-Hash", "<api-key>")
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://edge.p2p.org/api/defi/v1/transactions/swap/build")
.header("X-Client-Hash", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"inChain\": \"ethereum\",\n \"wallet\": \"<string>\",\n \"outTokenSymbol\": \"USR\",\n \"amount\": \"1000000\",\n \"route\": {},\n \"slippageBps\": 1000,\n \"provider\": \"kyberswap\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://edge.p2p.org/api/defi/v1/transactions/swap/build")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Client-Hash"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"inChain\": \"ethereum\",\n \"wallet\": \"<string>\",\n \"outTokenSymbol\": \"USR\",\n \"amount\": \"1000000\",\n \"route\": {},\n \"slippageBps\": 1000,\n \"provider\": \"kyberswap\"\n}"
response = http.request(request)
puts response.read_body{
"result": {
"inToken": {
"name": "<string>",
"ecosystem": "<string>",
"chain": "<string>",
"symbol": "<string>",
"decimals": 123,
"contractAddress": "<string>",
"logoURI": "<string>",
"priceUsd": 123,
"totalSupply": 123,
"isStakeable": true
},
"outToken": {
"name": "<string>",
"ecosystem": "<string>",
"chain": "<string>",
"symbol": "<string>",
"decimals": 123,
"contractAddress": "<string>",
"logoURI": "<string>",
"priceUsd": 123,
"totalSupply": 123,
"isStakeable": true
},
"provider": "<string>",
"spender": "<string>",
"willSpendAmount": "<string>",
"receive": "<string>",
"minReceive": "<string>",
"transaction": {
"to": "<string>",
"data": "<string>",
"value": "<string>",
"nonce": 123,
"gasLimit": "<string>",
"gasPrice": "<string>"
},
"expiresTimestamp": 123
},
"error": null,
"meta": {
"time": 123,
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"result": null,
"error": {
"name": "<string>",
"message": "<string>",
"validationErrors": [
{}
]
},
"meta": {
"time": 123,
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"result": null,
"error": {
"name": "<string>",
"message": "<string>",
"validationErrors": [
{}
]
},
"meta": {
"time": 123,
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}Authorizations
ClientHashApiKey
Body
application/json
Example:
"ethereum"
User wallet address (EOA).
Available options:
USDC, USDT Available options:
USR Amount in smallest units.
Example:
"1000000"
Opaque route data from /swap/quote endpoint.
Slippage tolerance in basis points.
Required range:
0 <= x <= 2000Example:
"kyberswap"
Related topics
Create a staking transactionCreate an unstaking transactionGet Yield StrategiesOverviewCreate Staking RequestCreate Swap Transaction
curl --request POST \
--url https://edge.p2p.org/api/defi/v1/transactions/swap/build \
--header 'Content-Type: application/json' \
--header 'X-Client-Hash: <api-key>' \
--data '
{
"inChain": "ethereum",
"wallet": "<string>",
"outTokenSymbol": "USR",
"amount": "1000000",
"route": {},
"slippageBps": 1000,
"provider": "kyberswap"
}
'import requests
url = "https://edge.p2p.org/api/defi/v1/transactions/swap/build"
payload = {
"inChain": "ethereum",
"wallet": "<string>",
"outTokenSymbol": "USR",
"amount": "1000000",
"route": {},
"slippageBps": 1000,
"provider": "kyberswap"
}
headers = {
"X-Client-Hash": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Client-Hash': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
inChain: 'ethereum',
wallet: '<string>',
outTokenSymbol: 'USR',
amount: '1000000',
route: {},
slippageBps: 1000,
provider: 'kyberswap'
})
};
fetch('https://edge.p2p.org/api/defi/v1/transactions/swap/build', 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://edge.p2p.org/api/defi/v1/transactions/swap/build",
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([
'inChain' => 'ethereum',
'wallet' => '<string>',
'outTokenSymbol' => 'USR',
'amount' => '1000000',
'route' => [
],
'slippageBps' => 1000,
'provider' => 'kyberswap'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Client-Hash: <api-key>"
],
]);
$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://edge.p2p.org/api/defi/v1/transactions/swap/build"
payload := strings.NewReader("{\n \"inChain\": \"ethereum\",\n \"wallet\": \"<string>\",\n \"outTokenSymbol\": \"USR\",\n \"amount\": \"1000000\",\n \"route\": {},\n \"slippageBps\": 1000,\n \"provider\": \"kyberswap\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Client-Hash", "<api-key>")
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://edge.p2p.org/api/defi/v1/transactions/swap/build")
.header("X-Client-Hash", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"inChain\": \"ethereum\",\n \"wallet\": \"<string>\",\n \"outTokenSymbol\": \"USR\",\n \"amount\": \"1000000\",\n \"route\": {},\n \"slippageBps\": 1000,\n \"provider\": \"kyberswap\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://edge.p2p.org/api/defi/v1/transactions/swap/build")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Client-Hash"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"inChain\": \"ethereum\",\n \"wallet\": \"<string>\",\n \"outTokenSymbol\": \"USR\",\n \"amount\": \"1000000\",\n \"route\": {},\n \"slippageBps\": 1000,\n \"provider\": \"kyberswap\"\n}"
response = http.request(request)
puts response.read_body{
"result": {
"inToken": {
"name": "<string>",
"ecosystem": "<string>",
"chain": "<string>",
"symbol": "<string>",
"decimals": 123,
"contractAddress": "<string>",
"logoURI": "<string>",
"priceUsd": 123,
"totalSupply": 123,
"isStakeable": true
},
"outToken": {
"name": "<string>",
"ecosystem": "<string>",
"chain": "<string>",
"symbol": "<string>",
"decimals": 123,
"contractAddress": "<string>",
"logoURI": "<string>",
"priceUsd": 123,
"totalSupply": 123,
"isStakeable": true
},
"provider": "<string>",
"spender": "<string>",
"willSpendAmount": "<string>",
"receive": "<string>",
"minReceive": "<string>",
"transaction": {
"to": "<string>",
"data": "<string>",
"value": "<string>",
"nonce": 123,
"gasLimit": "<string>",
"gasPrice": "<string>"
},
"expiresTimestamp": 123
},
"error": null,
"meta": {
"time": 123,
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"result": null,
"error": {
"name": "<string>",
"message": "<string>",
"validationErrors": [
{}
]
},
"meta": {
"time": 123,
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"result": null,
"error": {
"name": "<string>",
"message": "<string>",
"validationErrors": [
{}
]
},
"meta": {
"time": 123,
"requestId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}