Uniswap V3 Integration
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.
API
To exchange tokens, simply make a POST request to Openfort's exchange API:
https://api.openfort.io/v1/exchangeIn the body of the request:
- Include the contract addresses of the desired
tokenInAddressandtokenOutAddresstokens - Include a
fromAddressthat contains the address from which the token is swapped. - Include an
amountto 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:
- we first need to get the amount of OUT we can expect to get for 100 IN.
- then convert it with an
EXACT_INPUTto 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:
- here we first fetch the required amount of IN to obtain 10 OUT.
- then convert it with an
EXACT_OUTPUTto make sure get exactly 10 OUT.
Below is a sample cURL command for generating a new wallet for a user with Openfort:
curl https://api.openfort.io/v1/exchange \
-u "$YOUR_SECRET_KEY:" \
-d 'chainId=80002' \
-d 'fromAddress="0x45..."' \
-d 'tokenInAddress="0x45..."' \
-d 'tokenOutAddress="0x45..."' \
-d 'amount="100000"' \
-d 'tradeType=EXACT_INPUT'A successful response will include the new user object along with their user's ID (playerID), like below:
{
"id": "tin_c502d628-5bb3-42f2-b8f5-62ba4d71df3a",
"createdAt": 1689869074,
"object": "transactionIntent",
"abstractionType": "accountAbstractionV6",
"details": {
"userOperationHash": "0x25d3...005c",
"userOperation": {
"sender": "0x48930Cd730652bf0B18Ef8c80cD0Fa1Cc72A233E",
"nonce": "0x2",
"initCode": "0x",
"callData": "0xb61d...0000",
"callGasLimit": "0x27863",
"verificationGasLimit": "0x16001",
"preVerificationGas": "0xb818",
"maxFeePerGas": "0x62590091",
"maxPriorityFeePerGas": "0x62590091",
"paymasterAndData": "0x3210...b51c",
"signature": "0x6202...3d1b"
},
},
"chainId": 80002,
"updatedAt": 1689869074,
"policy": {
"id": "pol_..."
},
"player": {
"id": "pla_..."
},
"account": {
"id": "acc_..."
},
"response": {
"createdAt": 1689869074,
"logs": [
{
"removed": false,
"transactionIndex": 0,
"blockNumber": 44904492,
"transactionHash": "0x25d3...005c",
"address": "0x5FF1...2789",
"topics": [
"0xbb47...f972"
],
"data": "0x",
"logIndex": 0,
"blockHash": "0x8a69...6d59"
}
],
"blockNumber": 8789286,
"transactionHash": "0x25d3...005c",
"to": "0x0576...1B57",
"gasUsed": "336730",
"status": 1
},
"interactions": [
{
"functionName": "mint",
"value": "100000000000000",
"contract": "0x0576...1B57",
"functionArgs": [
"0x63B7...484f"
]
}
]
}