đ¸/transaction
Check the Prompt Guide to better prompt on Brian.
API calls to the /transaction
endpoint don't automatically execute transactions onchain. The /transaction
endpoint gives you back the data representing a standard transaction object! Learn more at the Transaction flow page.
Generate transaction(s) from a prompt.
POST
https://api.brianknows.org/api/v0/agent/transaction
This allows you to send a prompt to Brian and return a transaction calldata, ready to be executed onchain, and multiple transaction info parameters.
Some of the supported actions include:
swap
bridge
transfer
deposit and withdraw from DeFi protocols
ENS domain registration
Headers
x-brian-api-key*
String
Brian API key.
Content-Type*
application/json
Body content type.
Request Body
prompt*
String
User input prompt.
chainId
String
Chain ID of the user.
address*
String
Address that will send the transactions.
*mandatory parameters
If you don't pass the chainId
in the body, the source chain will be deducted from the prompt, if available. Otherwise, it will throw an error.
View below for some real examples.
{
"result": [
{
"solver": "",
"action": "",
"type": "",
"data": {
"description": "",
"steps": [
{
"chainId": ,
"blockNumber": ,
"from": "",
"to": "",
"gasLimit": "",
"data": "",
"value": "",
"protocol": {
"key": "",
"name": "",
"logoURI": ""
}
}
],
"gasCostUSD": "",
"fromChainId": ,
"fromAmountUSD": ,
"fromAmount": "",
"fromToken": {
"address": "",
"chainId": ,
"symbol": "",
"decimals": ,
"name": "",
"coinKey": "",
"logoURI": "",
"priceUSD": ""
},
"fromAddress": "",
"toChainId": ,
"toAmountUSD": ,
"toAmount": "",
"toAmountMin": "",
"toToken": {
"address": "",
"chainId": ,
"symbol": "",
"decimals": ,
"name": "",
"coinKey": "",
"logoURI": "",
"priceUSD": ""
},
"toAddress": "",
"receiver": "",
"protocol": {
"key": "",
"name": "",
"logoURI": ""
}
}
"extractedParams": {
"action": "",
"chain": "",
"token1": "",
"token2": "",
"address": "",
"amount": ""
},
"conversationHistory": [
{
"sender": "",
"content": ""
},
{
"sender": "",
"content": ""
}
]
}
]
}
API examples
Some real examples of API calls
EVM chains
Swap tokens
curl -XPOST "https://api.brianknows.org/api/v0/agent/transaction" -d '{"prompt": "I want to swap 10 USDC for ETH on base", "address": "0x9319b31838bba444CCeAeD025153a48AD6377471"}' -H "Content-Type: application/json" -H "x-brian-api-key: API_KEY"
Bridge tokens
curl -XPOST "https://api.brianknows.org/api/v0/agent/transaction" -d '{"prompt": "I want to bridge 10 USDC from Ethereum to Arbitrum", "address": "0x9319b31838bba444CCeAeD025153a48AD6377471"}' -H "Content-Type: application/json" -H "x-brian-api-key: API_KEY"
Deposit on DeFi protocol
curl -XPOST "https://api.brianknows.org/api/v0/agent/transaction" -d '{"prompt": "deposit 100 usdc to aave protocol on Ethereum", "address": "0xA9bC8A58B39935BA3D8D1Ce4b0d3383153F184E1"}' -H "Content-Type: application/json" -H "x-brian-api-key: API_KEY"
Starknet
Transfer tokens
curl -XPOST "https://api.brianknows.org/api/v0/agent/transaction" -d '{"prompt": "transfer 10 usdc to 0x05288402db9a6260a5edfeeb6e5922fd103280e579d103106788a2a33b42fc73 on starknet", "address": "0x0309e6b209031362268d62d646a067365e6f6d6eb7f571b5212cbdfd5f26fe54"}' -H "Content-Type: application/json" -H "x-brian-api-key: API_KEY"
Swap tokens
curl -XPOST "https://api.brianknows.org/api/v0/agent/transaction" -d '{"prompt": "swap 10 usdc to eth on starknet", "address": "0x0309e6b209031362268d62d646a067365e6f6d6eb7f571b5212cbdfd5f26fe54"}' -H "Content-Type: application/json" -H "x-brian-api-key: API_KEY"
Solana
Transfer tokens
curl -XPOST "https://api.brianknows.org/api/v0/agent/transaction" -d '{"prompt": "transfer 2 sol to CnXMWB8W7bcnADsZsJAJYkcuu8jr392ZFvxDBiumW3ww on solana", "address": "53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr"}' -H "Content-Type: application/json" -H "x-brian-api-key: API_KEY"
Swap tokens
curl -XPOST "https://api.brianknows.org/api/v0/agent/transaction" -d '{"prompt": "swap 2 sol to usdc on solana", "address": "53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr"}' -H "Content-Type: application/json" -H "x-brian-api-key: API_KEY"
Allowance and Approval management
For EVMs and Starknet, the steps
array will contain an approve transaction as the first position when needed according to the transaction involved.
It first checks the existing allowance and returns a transaction approving the exact amount needed.
For example, if the transaction involves a native token as the input token, the steps array will not contain the approve transaction. If the transaction involves an ERC20 token as the input token and the existing allowance covers the amount to spend, the steps array will not contain the approve transaction. Finally, suppose the transaction involves an ERC20 token as the input token and the existing allowance doesn't cover the amount to spend. In that case, the steps array will contain the approve transaction in the first position.
Here is an example of a USDC swap:
...
"steps": [
// Approve transaction first
{
"chainId": 1,
"blockNumber": 20427040,
"from": "0x9319b31838bba444CCeAeD025153a48AD6377471",
"to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"gasLimit": "80000",
"data": "0x095ea7b300000000000000000000000080eba3855878739f4710233a8a19d89bdd2ffb8e0000000000000000000000000000000000000000000000000000000005f5e100",
"value": "0"
},
// Swap transaction in second place
{
"chainId": 1,
"blockNumber": 20427040,
"from": "0x9319b31838bba444CCeAeD025153a48AD6377471",
"to": "0x80EbA3855878739F4710233A8a19d89Bdd2ffB8E",
"gasLimit": "358072",
"data": "0xb35d7e73000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000009a9059cbb010001ffffffffffa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48095ea7b3010203ffffffffffa0b86991c6218b36c1d19d4a2e9eb0ce3606eb4870a082310104ffffffffff0298c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5ce8eda9df0105030406ffffff87870bca3f3fd6335c3f4ce8392d69350b4fa4e270a082310104ffffffffff0498c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5cb67d77c5010402ffffffff04ca99eaa38e8f37a168214a3a57c9a45a58563ed5a9059cbb010704ffffffffff98c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5c6e7a43a3010408ffffffff047e7d64d987cab6eed08a191c4c2459daf2f8ed0b241c59120104ffffffffffff7e7d64d987cab6eed08a191c4c2459daf2f8ed0b00000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000129b480ad625bcd1a5c3a1c10d708114726fa467000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000087870bca3f3fd6335c3f4ce8392d69350b4fa4e200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000005f45a6000000000000000000000000000000000000000000000000000000000000000200000000000000000000000007d585b0e27bbb3d981b7757115ec11f47c4769940000000000000000000000000000000000000000000000000000000000000020000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000009319b31838bba444cceaed025153a48ad637747100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000005c69f58",
"value": "0"
}
],
...
Last updated