Pay

Execute a swap and a payment in a single transaction.

post
/pay

https://api.totle.com/pay
This endpoint allows payments to be made to a specified address.
Request
Response
Request
Body Parameters
apiKey
optional
string
The Totle partner ID
partnerContract
optional
string
The smart conntract address if you're a Totle partner
address
optional
string
The msg.sender wallet address. Although optional, you will only receive a payload if you include the address
config
optional
object
Transaction/trade-related configuration options
config.exchanges
optional
object
Information about the exchanges to be used (or not used)
config.exchanges.list
optional
array
IDs of the exchanges to whitelist/blacklist. Use /exchanges endpoint for IDs to use (array of integers)
config.exchanges.type
optional
string
Whether the exchange(s) should be whitelisted/blacklisted. Use white for whitelisting and black for blacklisting
config.transactions
optional
boolean
Whether transaction objects are returned or not. Setting this to true will require you to include address. If you just want to get the rate, set this to false
config.fillNonce
optional
boolean
Whether the nonce field in the transaction objects are populated or not. Defaults to true
config.skipBalanceChecks
optional
boolean
Whether the API should validate the source asset balance of the wallet given in the address field. Defaults to true
swap
required
object
Information about the single swap to be executed (submit either swap OR swaps ; do not submit both to the API)
swap.sourceAsset
required
string
Identifier of the token to sell (either token address OR symbol)
swap.destinationAsset
required
string
Identifier of the token to buy (either token address OR symbol)
swap.destinationAmount
required
integer
The amount of tokens to be paid to the destinationAddress
swap.maxSource
optional
integer
The maximum amount of token to be sold when all costs are factored in
swap.destinationAddress
required
string
The wallet to which the destinationAsset should be paid to
Response
200: OK
If the payment was successful.
{
"success": true,
"response": {
"id": "0x...353",
"summary": [ ... ],
"transactions": [ ... ],
"expiration": { ... }
}
}
For failures:
{
"success": false,
"response": {
"code": 3100,
"name": "Error Name",
"message": "Error message",
"link": "",
"info": "Detailed error information"
}
}
cURL
Node
Ruby
JavaScript
Python
cURL
curl -X POST \
https://api.totle.com/pay \
-H 'content-type: Application/JSON' \
-d '{"swap":{"sourceAsset":"ETH","destinationAsset":"DAI","destinationAmount":"1000000000000000000", "destinationAddress": "0x583d03451406d179182efc742a1d811a9e34c36b"}}'
Node
var request = require("request")
var body = {
"swap": {
"sourceAsset": "ETH",
"destinationAsset": "DAI",
"destinationAmount": "1000000000000000000",
"destinationAddress": "0x583d03451406d179182efc742a1d811a9e34c36b"
}
}
var options = {
method: 'POST',
url: 'https://api.totle.com/swap',
headers: {'content-type': 'application/json'},
body: JSON.stringify(body)
}
request(options, function (error, response, body) {
if (error) throw new Error(error)
console.log(body)
})
Ruby
require 'uri'
require 'net/http'
url = URI("https://api.totle.com/pay")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["content-type"] = 'Application/JSON'
request.body = "{\"swap\":{\"sourceAsset\":\"ETH\",\"destinationAsset\":\"DAI\",\"destinationAmount\":\"1000000000000000000\", \"destinationAddress\": \"0x583d03451406d179182efc742a1d811a9e34c36b\"}}"
response = http.request(request)
puts response.read_body
JavaScript
var data = "{\"swap\":{\"sourceAsset\":\"ETH\",\"destinationAsset\":\"DAI\",\"destinationAmount\":\"1000000000000000000\", \"destinationAddress\": \"0x583d03451406d179182efc742a1d811a9e34c36b\"}}";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.totle.com/pay");
xhr.setRequestHeader("content-type", "Application/JSON");
xhr.send(data);
Python
import requests
url = "https://api.totle.com/pay"
payload = "{\"swap\":{\"sourceAsset\":\"ETH\",\"destinationAsset\":\"DAI\",\"destinationAmount\":\"1000000000000000000\", \"destinationAddress\": \"0x583d03451406d179182efc742a1d811a9e34c36b\"}}"
headers = {
'content-type': "Application/JSON"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)