Management API Reference

Uniswap V3 integration

Learn how to implement swaps in your app.

The API allows you to convert any tokens, using Uniswap V3. Conversion rates are determined via an Automated Market Maker mechanism, and depend on supply and demand of the respective tokens.

To exchange tokens, simply make a POST request to Openfort's exchange API:


_10
https://api.openfort.xyz/v1/exchange

In the body of the request:

  • Include the contract addresses of the desired tokenInAddress and tokenOutAddress tokens
  • Include a fromAddress that contains the address from which the token is swapped.
  • Include an amount to swap, either a desired input and output token amount.

Depending on the "direction" of the conversion, there are two different tradeTypes, which are covered with examples below too. Let's assume we have two tokens IN and OUT:

Converting with an exact input amount#

  • The player wants to swap 100 IN to OUT:
  1. we first need to get the amount of OUT we can expect to get for 100 IN.
  2. then convert it with an EXACT_INPUT to make sure we get the highest amount of OUT for our 100 IN.

Converting with an exact output amount#

  • The player wants to buy 10 OUT:
  1. here we first fetch the required amount of IN to obtain 10 OUT.
  2. then convert it with an EXACT_OUTPUT to make sure get exactly 10 OUT.

Below is a sample cURL command for generating a new wallet for a user with Openfort:

command-line

_10
curl https://api.openfort.xyz/v1/exchange \
_10
-u "$YOUR_SECRET_KEY:" \
_10
-d 'chainId=80002' \
_10
-d 'fromAddress="0x45..."' \
_10
-d 'tokenInAddress="0x45..."' \
_10
-d 'tokenOutAddress="0x45..."' \
_10
-d 'amount="100000"' \
_10
-d 'tradeType=EXACT_INPUT'

A successful response will include the new user object along with their user's ID (playerID), like below:

json

_66
{
_66
"id": "tin_c502d628-5bb3-42f2-b8f5-62ba4d71df3a",
_66
"createdAt": 1689869074,
_66
"object": "transactionIntent",
_66
"abstractionType": "accountAbstractionV6",
_66
"details": {
_66
"userOperationHash": "0x25d3...005c",
_66
"userOperation": {
_66
"sender": "0x48930Cd730652bf0B18Ef8c80cD0Fa1Cc72A233E",
_66
"nonce": "0x2",
_66
"initCode": "0x",
_66
"callData": "0xb61d...0000",
_66
"callGasLimit": "0x27863",
_66
"verificationGasLimit": "0x16001",
_66
"preVerificationGas": "0xb818",
_66
"maxFeePerGas": "0x62590091",
_66
"maxPriorityFeePerGas": "0x62590091",
_66
"paymasterAndData": "0x3210...b51c",
_66
"signature": "0x6202...3d1b"
_66
},
_66
},
_66
"chainId": 80002,
_66
"updatedAt": 1689869074,
_66
"policy": {
_66
"id": "pol_..."
_66
},
_66
"player": {
_66
"id": "pla_..."
_66
},
_66
"account": {
_66
"id": "acc_..."
_66
},
_66
"response": {
_66
"createdAt": 1689869074,
_66
"logs": [
_66
{
_66
"removed": false,
_66
"transactionIndex": 0,
_66
"blockNumber": 44904492,
_66
"transactionHash": "0x25d3...005c",
_66
"address": "0x5FF1...2789",
_66
"topics": [
_66
"0xbb47...f972"
_66
],
_66
"data": "0x",
_66
"logIndex": 0,
_66
"blockHash": "0x8a69...6d59"
_66
}
_66
],
_66
"blockNumber": 8789286,
_66
"transactionHash": "0x25d3...005c",
_66
"to": "0x0576...1B57",
_66
"gasUsed": "336730",
_66
"status": 1
_66
},
_66
"interactions": [
_66
{
_66
"functionName": "mint",
_66
"value": "100000000000000",
_66
"contract": "0x0576...1B57",
_66
"functionArgs": [
_66
"0x63B7...484f"
_66
]
_66
}
_66
]
_66
}

Check the Quote Swap endpoint to get a quotation before executing the conversion.