Download OpenAPI specification:Download
Token Swaps are a mechanism to allow two parties to securely trade tokens. Each swap is made up of two trades between the swap initiator and the counterparty. One trade per token contract. For a swap to work, the initiator creates a trade to transfer the token(s) owned by the initiator to the counterparty. In response, the counterparty creates a 2nd trade to transfer the token(s) owned by the counterparty to the initiator.
Token Trades are part of a Token Swap. Each swap is made up of two trades between the swap initiator and the counterparty. One trade per token contract. For a swap to work, the initiator creates a trade to transfer the token(s) owned by the initiator to the counterparty. In response, the counterparty creates a 2nd trade to transfer the token(s) owned by the counterparty to the initiator.
The Token Swap service makes it trivial to trade tokens across token contracts in an atomic manner. Utilizing the Hashed Timelock Contract under the cover, tokens can be securely traded such that the parties of the trades never lose their tokens due to fraud behaviors of their trading partners. The multiple steps involved in the trading flow are all exposed as simple-to-use REST endpoints.
Kaleido API for marketplace services are authenticated using application credentials. The username and password must be created in the environment containing the service instance as "Application Credentials". For more details see the documentation on App Credentials.
Security Scheme Type | HTTP |
---|---|
HTTP Authorization Scheme | basic |
token-address required | string The address of the Token Contract |
from required | string The from account address to debit the token(s) from |
to required | string The target account address to receive the token(s) |
amount | string The amount of tokens to trade (erc20 only) |
token-id | string The tokenId to trade (erc721 only) |
timeout | integer The number of seconds before the trade times out and tokens are able to be refunded |
hash-lock | string The hash lock that must be sent if responding to a token swap trade offer |
{- "token-address": "string",
- "from": "string",
- "to": "string",
- "amount": "string",
- "token-id": "string",
- "timeout": 0,
- "hash-lock": "string"
}
{- "secret": "string",
- "hash-lock": "string",
- "trade-id": "string"
}
trade_id required | string |
{- "sender": "string",
- "receiver": "string",
- "token-contract": "string",
- "hash-lock": "string",
- "time-lock": 0,
- "withdrawn": true,
- "refunded": true,
- "secret": "string",
- "token-id": "string",
- "amount": "string"
}
trade_id required | string |
secret required | string The secret that is used to claim the tokens from a completed trade |
from required | string The from account address used to sign the withdraw transaction |
{- "secret": "string",
- "from": "string"
}
{- "transactionHash": "string",
- "success": true
}
trade_id required | string |
from required | string The from account address used to sign the refund transaction |
{- "from": "string"
}
{- "transactionHash": "string",
- "success": true
}
hash_lock required | string |
secret required | string The secret to store |
{- "secret": "string"
}
{- "success": true
}
[- {
- "initiator": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string"
}, - "counterparty": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string",
- "secret": "string"
}
}
]
hash_lock required | string |
{- "initiator": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string"
}, - "counterparty": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string",
- "secret": "string"
}
}
trade_id required | string |
{- "initiator": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string"
}, - "counterparty": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string",
- "secret": "string"
}
}
sender required | string |
[- {
- "initiator": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string"
}, - "counterparty": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string",
- "secret": "string"
}
}
]
receiver required | string |
[- {
- "initiator": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string"
}, - "counterparty": {
- "tradeId": "string",
- "sender": "string",
- "receiver": "string",
- "tokenContract": "string",
- "value": "string",
- "hashlock": "string",
- "timelock": 0,
- "status": "string",
- "secret": "string"
}
}
]