Authorise an agent
curl --request POST \
--url https://api.gains.trade/v1/{chain}/agents \
--header 'Content-Type: application/json' \
--data '
{
"trader": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"agent": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"scope": {
"markets": "all",
"maxLeverage": "0.5",
"dailySpendCapUsd": "0.5",
"expiresAt": 123
},
"timestamp": 123,
"signature": "0xabc123",
"name": "<string>"
}
'import requests
url = "https://api.gains.trade/v1/{chain}/agents"
payload = {
"trader": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"agent": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"scope": {
"markets": "all",
"maxLeverage": "0.5",
"dailySpendCapUsd": "0.5",
"expiresAt": 123
},
"timestamp": 123,
"signature": "0xabc123",
"name": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
trader: '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523',
agent: '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523',
scope: {markets: 'all', maxLeverage: '0.5', dailySpendCapUsd: '0.5', expiresAt: 123},
timestamp: 123,
signature: '0xabc123',
name: '<string>'
})
};
fetch('https://api.gains.trade/v1/{chain}/agents', 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://api.gains.trade/v1/{chain}/agents",
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([
'trader' => '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523',
'agent' => '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523',
'scope' => [
'markets' => 'all',
'maxLeverage' => '0.5',
'dailySpendCapUsd' => '0.5',
'expiresAt' => 123
],
'timestamp' => 123,
'signature' => '0xabc123',
'name' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"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://api.gains.trade/v1/{chain}/agents"
payload := strings.NewReader("{\n \"trader\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"agent\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"scope\": {\n \"markets\": \"all\",\n \"maxLeverage\": \"0.5\",\n \"dailySpendCapUsd\": \"0.5\",\n \"expiresAt\": 123\n },\n \"timestamp\": 123,\n \"signature\": \"0xabc123\",\n \"name\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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://api.gains.trade/v1/{chain}/agents")
.header("Content-Type", "application/json")
.body("{\n \"trader\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"agent\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"scope\": {\n \"markets\": \"all\",\n \"maxLeverage\": \"0.5\",\n \"dailySpendCapUsd\": \"0.5\",\n \"expiresAt\": 123\n },\n \"timestamp\": 123,\n \"signature\": \"0xabc123\",\n \"name\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gains.trade/v1/{chain}/agents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"trader\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"agent\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"scope\": {\n \"markets\": \"all\",\n \"maxLeverage\": \"0.5\",\n \"dailySpendCapUsd\": \"0.5\",\n \"expiresAt\": 123\n },\n \"timestamp\": 123,\n \"signature\": \"0xabc123\",\n \"name\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"agent": {
"agent": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"trader": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"name": "<string>",
"scope": {
"markets": "all",
"maxLeverage": "0.5",
"dailySpendCapUsd": "0.5",
"expiresAt": 123,
"permissions": "trade"
},
"mode": "self",
"status": "pending_delegation",
"createdAt": 123
},
"delegationTx": {
"to": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"data": "0xabc123",
"chainId": 123
}
}{
"code": "VALIDATION_ERROR",
"message": "<string>",
"details": {}
}{
"code": "VALIDATION_ERROR",
"message": "<string>",
"details": {}
}Agents
Authorise an agent
Registers the agent and its scope, signed by the trader’s master wallet (EIP-712 AgentAuthorization). The response carries the setTradingDelegate transaction the master wallet must send; the agent becomes active once it is mined.
POST
/
v1
/
{chain}
/
agents
Authorise an agent
curl --request POST \
--url https://api.gains.trade/v1/{chain}/agents \
--header 'Content-Type: application/json' \
--data '
{
"trader": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"agent": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"scope": {
"markets": "all",
"maxLeverage": "0.5",
"dailySpendCapUsd": "0.5",
"expiresAt": 123
},
"timestamp": 123,
"signature": "0xabc123",
"name": "<string>"
}
'import requests
url = "https://api.gains.trade/v1/{chain}/agents"
payload = {
"trader": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"agent": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"scope": {
"markets": "all",
"maxLeverage": "0.5",
"dailySpendCapUsd": "0.5",
"expiresAt": 123
},
"timestamp": 123,
"signature": "0xabc123",
"name": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
trader: '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523',
agent: '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523',
scope: {markets: 'all', maxLeverage: '0.5', dailySpendCapUsd: '0.5', expiresAt: 123},
timestamp: 123,
signature: '0xabc123',
name: '<string>'
})
};
fetch('https://api.gains.trade/v1/{chain}/agents', 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://api.gains.trade/v1/{chain}/agents",
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([
'trader' => '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523',
'agent' => '0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523',
'scope' => [
'markets' => 'all',
'maxLeverage' => '0.5',
'dailySpendCapUsd' => '0.5',
'expiresAt' => 123
],
'timestamp' => 123,
'signature' => '0xabc123',
'name' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"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://api.gains.trade/v1/{chain}/agents"
payload := strings.NewReader("{\n \"trader\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"agent\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"scope\": {\n \"markets\": \"all\",\n \"maxLeverage\": \"0.5\",\n \"dailySpendCapUsd\": \"0.5\",\n \"expiresAt\": 123\n },\n \"timestamp\": 123,\n \"signature\": \"0xabc123\",\n \"name\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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://api.gains.trade/v1/{chain}/agents")
.header("Content-Type", "application/json")
.body("{\n \"trader\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"agent\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"scope\": {\n \"markets\": \"all\",\n \"maxLeverage\": \"0.5\",\n \"dailySpendCapUsd\": \"0.5\",\n \"expiresAt\": 123\n },\n \"timestamp\": 123,\n \"signature\": \"0xabc123\",\n \"name\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gains.trade/v1/{chain}/agents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"trader\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"agent\": \"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523\",\n \"scope\": {\n \"markets\": \"all\",\n \"maxLeverage\": \"0.5\",\n \"dailySpendCapUsd\": \"0.5\",\n \"expiresAt\": 123\n },\n \"timestamp\": 123,\n \"signature\": \"0xabc123\",\n \"name\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"agent": {
"agent": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"trader": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"name": "<string>",
"scope": {
"markets": "all",
"maxLeverage": "0.5",
"dailySpendCapUsd": "0.5",
"expiresAt": 123,
"permissions": "trade"
},
"mode": "self",
"status": "pending_delegation",
"createdAt": 123
},
"delegationTx": {
"to": "0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523",
"data": "0xabc123",
"chainId": 123
}
}{
"code": "VALIDATION_ERROR",
"message": "<string>",
"details": {}
}{
"code": "VALIDATION_ERROR",
"message": "<string>",
"details": {}
}Path Parameters
Available options:
arbitrum, base, polygon, megaeth, arbitrum-sepolia Example:
"arbitrum"
Body
application/json
Agent, scope and master signature
Pattern:
^0x[0-9a-fA-F]{40}$Example:
"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523"
Pattern:
^0x[0-9a-fA-F]{40}$Example:
"0x73b3A111C5BCCf9086c97B96e0AbAad69Dc4f523"
Show child attributes
Show child attributes
EIP-712 AgentAuthorization signature by the trader's master wallet.
Pattern:
^0x[0-9a-fA-F]*$Example:
"0xabc123"
Maximum string length:
32