💸/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

Check the next page for a comprehensive overview of actions and chains supported.

Headers

Name
Type
Description

x-brian-api-key*

String

Brian API key.

Content-Type*

application/json

Body content type.

Request Body

Name
Type
Description

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"
Response
{
  "result": [
    {
      "solver": "Enso",
      "action": "swap",
      "type": "write",
      "data": {
        "description": "You are about to swap 10.000000 USDC($10.00) for 0.002988 ETH ($9.96) on Base using Enso solver. The address receiver is 0x9319...7471.",
        "steps": [
          {
            "chainId": 8453,
            "blockNumber": 17822776,
            "from": "0x9319b31838bba444CCeAeD025153a48AD6377471",
            "to": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
            "gasLimit": "80000",
            "data": "0x095ea7b300000000000000000000000080eba3855878739f4710233a8a19d89bdd2ffb8e0000000000000000000000000000000000000000000000000000000000989680",
            "value": "0"
          },
          {
            "chainId": 8453,
            "blockNumber": 17822776,
            "from": "0x9319b31838bba444CCeAeD025153a48AD6377471",
            "to": "0x80EbA3855878739F4710233A8a19d89Bdd2ffB8E",
            "gasLimit": "453028",
            "data": "0xb35d7e73000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda029130000000000000000000000000000000000000000000000000000000000989680000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000008a9059cbb010001ffffffffff833589fcd6edb6e08f4c7c32d4f71b54bda02913095ea7b3010203ffffffffff833589fcd6edb6e08f4c7c32d4f71b54bda0291319198595a30485ffffffff85def1c0ded9bec7f1a1670819833240f027b25eff9bd3b227018504ffffffff056675a323dedb77822fcf39eaa9d682f6abe72555ddcd52200105ffffffffff057e7d64d987cab6eed08a191c4c2459daf2f8ed0b19198595a30586ffffffffff9319b31838bba444cceaed025153a48ad63774716e7a43a3010507ffffffff057e7d64d987cab6eed08a191c4c2459daf2f8ed0b241c59120105ffffffffffff7e7d64d987cab6eed08a191c4c2459daf2f8ed0b000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000aa00000000000000000000000000000000000000000000000000000000000000ac00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000129b480ad625bcd1a5c3a1c10d708114726fa467000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000986f70000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000828415565b0000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000986f70000000000000000000000000000000000000000000000000000a4c14a690bf9d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000004600000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000420000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000986f70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000012556e69737761705633000000000000000000000000000000000000000000000000000000000000000000000000986f70000000000000000000000000000000000000000000000000000a500a6d210dd7000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000002626664c2603336e57b271c5c0b26f421741e481000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000042833589fcd6edb6e08f4c7c32d4f71b54bda0291300006450c5725949a6f0c72e6c4a641f24049a917db0cb0001f442000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000400000000000000000000000004200000000000000000000000000000000000006ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000000000000000000000000000000003f5c6904e3a000000000000000000000000ad01c20d5886137e056775af56915de824c8fce50000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda029130000000000000000000000000000000000000000000000000000000000000000869584cd000000000000000000000000100000000000000000000000000000000000001100000000000000000000000000000000000000005b210060dff63345919e860400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000a4c3321aed839",
            "value": "0"
          }
        ],
        "gasCostUSD": "",
        "fromChainId": 8453,
        "fromAmountUSD": "10",
        "fromAmount": "10000000",
        "fromToken": {
          "address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "chainId": 8453,
          "symbol": "USDC",
          "decimals": 6,
          "name": "USD Coin",
          "coinKey": "USDC",
          "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
          "priceUSD": "1"
        },
        "fromAddress": "0x9319b31838bba444CCeAeD025153a48AD6377471",
        "toChainId": 8453,
        "toAmountUSD": "9.957563936252797",
        "toAmount": "2988177586862245",
        "toAmountMin": "2988177586862245",
        "toToken": {
          "address": "0x0000000000000000000000000000000000000000",
          "chainId": 8453,
          "symbol": "ETH",
          "decimals": 18,
          "name": "ETH",
          "coinKey": "ETH",
          "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
          "priceUSD": "3332.32"
        },
        "toAddress": "0x80EbA3855878739F4710233A8a19d89Bdd2ffB8E",
        "receiver": "0x9319b31838bba444CCeAeD025153a48AD6377471",
        "protocol": {
          "key": "enso",
          "name": "enso",
          "logoURI": ""
        }
      }
    }
  ]
}

The steps array can contain a list of possible swap routes that the user can choose from. In some cases, it could return just one step.

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"
Response
{
  "result": [
    {
      "solver": "Bungee",
      "action": "bridge",
      "type": "write",
      "data": {
        "description": "You are about to bridge 10.000000 USDC for 9.975330 USDC ($10.00) from Ethereum to Arbitrum one using Bungee solver. The address receiver is 0x9319...7471.",
        "steps": [
          {
            "chainId": 1,
            "blockNumber": 20427034,
            "from": "0x9319b31838bba444CCeAeD025153a48AD6377471",
            "to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
            "gasLimit": "80000",
            "data": "0x095ea7b30000000000000000000000003a23f943181408eac424116af7b7790c94cb97a50000000000000000000000000000000000000000000000000000000000989680",
            "value": "0"
          },
          {
            "chainId": 1,
            "blockNumber": 20427034,
            "from": "0x9319b31838bba444CCeAeD025153a48AD6377471",
            "to": "0x3a23F943181408EAC424116Af7b7790c94Cb97a5",
            "gasLimit": "500000",
            "data": "0x000001ad792ebcb90000000000000000000000000000000000000000000000000000000000989680000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000605c00000000000000000000000000000000000000000000000000000000000009ea00000000000000000000000000000000000000000000000000000000000000020000000000000000000000009319b31838bba444cceaed025153a48ad63774710000000000000000000000009319b31838bba444cceaed025153a48ad63774710000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000983624000000000000000000000000000000000000000000000000000000000000a4b100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000066aa44c70000000000000000000000000000000000000000000000000000000066aa98cdd00dfeeddeadbeef765753be7f7a64d5509974b0d678e1e3149b02f4",
            "value": "0x00"
          }
        ],
        "gasCostUSD": "",
        "fromChainId": 1,
        "fromAmountUSD": "10",
        "fromAmount": "10000000",
        "fromToken": {
          "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
          "chainId": 1,
          "symbol": "USDC",
          "decimals": 6,
          "name": "USD Coin",
          "coinKey": "USDC",
          "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
          "priceUSD": "1"
        },
        "fromAddress": "0x9319b31838bba444CCeAeD025153a48AD6377471",
        "toChainId": 42161,
        "toAmountUSD": "9.97533",
        "toAmount": "9975332",
        "toAmountMin": "9975332",
        "toToken": {
          "address": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
          "chainId": 42161,
          "symbol": "USDC",
          "decimals": 6,
          "name": "USD Coin",
          "coinKey": "USDC",
          "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
          "priceUSD": "1"
        },
        "toAddress": "0x3a23F943181408EAC424116Af7b7790c94Cb97a5",
        "receiver": "0x9319b31838bba444CCeAeD025153a48AD6377471",
        "protocol": {
          "key": "across",
          "name": "Across",
          "logoURI": "https://miro.medium.com/max/800/1*PN_F5yW4VMBgs_xX-fsyzQ.png"
        }
      }
    }
  ]
}

The steps array can contain a list of possible swap routes that the user can choose from. In some cases, it could return just one step.

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"
Response
{
  "result": [
    {
      "solver": "Enso",
      "action": "deposit",
      "type": "write",
      "data": {
        "description": "You are about to deposit 100.000000 USDC ($100.00) into aave-v3 protocol, obtaining 99.900000 AETHUSDC on Ethereum. The address receiver is: 0x9319...7471.",
        "steps": [
          {
            "chainId": 1,
            "blockNumber": 20427040,
            "from": "0x9319b31838bba444CCeAeD025153a48AD6377471",
            "to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
            "gasLimit": "80000",
            "data": "0x095ea7b300000000000000000000000080eba3855878739f4710233a8a19d89bdd2ffb8e0000000000000000000000000000000000000000000000000000000005f5e100",
            "value": "0"
          },
          {
            "chainId": 1,
            "blockNumber": 20427040,
            "from": "0x9319b31838bba444CCeAeD025153a48AD6377471",
            "to": "0x80EbA3855878739F4710233A8a19d89Bdd2ffB8E",
            "gasLimit": "358072",
            "data": "0xb35d7e73000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000009a9059cbb010001ffffffffffa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48095ea7b3010203ffffffffffa0b86991c6218b36c1d19d4a2e9eb0ce3606eb4870a082310104ffffffffff0298c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5ce8eda9df0105030406ffffff87870bca3f3fd6335c3f4ce8392d69350b4fa4e270a082310104ffffffffff0498c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5cb67d77c5010402ffffffff04ca99eaa38e8f37a168214a3a57c9a45a58563ed5a9059cbb010704ffffffffff98c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5c6e7a43a3010408ffffffff047e7d64d987cab6eed08a191c4c2459daf2f8ed0b241c59120104ffffffffffff7e7d64d987cab6eed08a191c4c2459daf2f8ed0b00000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000129b480ad625bcd1a5c3a1c10d708114726fa467000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000087870bca3f3fd6335c3f4ce8392d69350b4fa4e200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000005f45a6000000000000000000000000000000000000000000000000000000000000000200000000000000000000000007d585b0e27bbb3d981b7757115ec11f47c4769940000000000000000000000000000000000000000000000000000000000000020000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000009319b31838bba444cceaed025153a48ad637747100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000005c69f58",
            "value": "0"
          }
        ],
        "gasCostUSD": "",
        "fromChainId": 1,
        "fromAmountUSD": "100",
        "fromAmount": "100000000",
        "fromToken": {
          "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
          "chainId": 1,
          "symbol": "USDC",
          "decimals": 6,
          "name": "USD Coin",
          "coinKey": "USDC",
          "logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
          "priceUSD": "1"
        },
        "fromAddress": "0x9319b31838bba444CCeAeD025153a48AD6377471",
        "toChainId": 1,
        "toAmountUSD": "99.9",
        "toAmount": "100000000",
        "toAmountMin": "100000000",
        "toToken": {
          "address": "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c",
          "chainId": 1,
          "symbol": "aEthUSDC",
          "decimals": 6,
          "name": "Aave Ethereum USDC",
          "coinKey": "aEthUSDC",
          "logoURI": "https://static.debank.com/image/eth_token/logo_url/0x98c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5c/d1e0d14800c1e4657fb8c25e0f073cf0.png",
          "priceUSD": "1"
        },
        "toAddress": "0x80EbA3855878739F4710233A8a19d89Bdd2ffB8E",
        "receiver": "0x9319b31838bba444CCeAeD025153a48AD6377471",
        "protocol": {
          "key": "aave-v3",
          "name": "aave-v3",
          "logoURI": ""
        }
      }
    }
  ]
}


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"
Response
{
  "result": [
    {
      "solver": "Brian-Starknet",
      "action": "transfer",
      "type": "write",
      "data": {
        "description": "You are about to send 10 USDC ($10.0) to 0x05288402db9a6260a5edfeeb6e5922fd103280e579d103106788a2a33b42fc73 on Starknet.",
        "steps": [
          {
            "contractAddress": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
            "entrypoint": "transfer",
            "calldata": [
              "2333149233072038891240751670574223940282370554046219129156039053790278777971",
              "10000000",
              "0"
            ]
          }
        ],
        "fromChainId": "SN_MAINNET(custom chainId 4012)",
        "fromAmount": "10000000",
        "fromToken": {
          "address": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
          "symbol": "usdc",
          "decimals": 6
        },
        "fromAddress": "0x0309e6b209031362268d62d646a067365e6f6d6eb7f571b5212cbdfd5f26fe54",
        "toChainId": "SN_MAINNET(custom chainId 4012)",
        "toAmount": "10000000",
        "toAmountMin": "10000000",
        "toToken": {
          "address": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
          "symbol": "usdc",
          "decimals": 6
        },
        "toAddress": "0x05288402db9a6260a5edfeeb6e5922fd103280e579d103106788a2a33b42fc73",
        "receiver": "0x05288402db9a6260a5edfeeb6e5922fd103280e579d103106788a2a33b42fc73"
      },
      "extractedParams": {
        "action": "transfer",
        "token1": "usdc",
        "chain": "starknet",
        "address": "0x05288402db9a6260a5edfeeb6e5922fd103280e579d103106788a2a33b42fc73",
        "amount": "10"
      },
      "conversationHistory": [
        {
          "sender": "user",
          "content": "transfer 10 usdc to 0x05288402db9a6260a5edfeeb6e5922fd103280e579d103106788a2a33b42fc73 on starknet"
        },
        {
          "sender": "brian",
          "content": "You are about to send 10 USDC ($10.0) to 0x05288402db9a6260a5edfeeb6e5922fd103280e579d103106788a2a33b42fc73 on Starknet."
        }
      ]
    }
  ]
}

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"
Response
{
  "result": [
    {
      "solver": "Avnu.fi",
      "action": "swap",
      "type": "write",
      "data": {
        "description": "You are about to swap 10.0 USDC ($9.9) for 0.0025 ETH ($10.0) on Starknet using Avnu.fi solver. The address receiver is 0x0309e6b209031362268d62d646a067365e6f6d6eb7f571b5212cbdfd5f26fe54.",
        "steps": [
          {
            "contractAddress": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
            "entrypoint": "approve",
            "calldata": [
              "1878172929613570324457239593384623395652998589633516919063222269774660188943",
              "10000000",
              "0"
            ]
          },
          {
            "contractAddress": "0x4270219d365d6b017231b52e92b3fb5d7c8378b05e9abc97724537a80e93b0f",
            "entrypoint": "multi_route_swap",
            "calldata": [
              "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
              "0x989680",
              "0x0",
              "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
              "0x90ce50d6cc4bf",
              "0x0",
              "0x8c7634d05aa5d",
              "0x0",
              "0x309e6b209031362268d62d646a067365e6f6d6eb7f571b5212cbdfd5f26fe54",
              "0x1",
              "0x129b480ad625bcd1a5c3a1c10d708114726fa467",
              "0x1",
              "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
              "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
              "0x5dd3d2f4429af886cd1a3b08289dbcea99a294197e9eb43b0e0325b4b",
              "0xe8d4a51000",
              "0x6",
              "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
              "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
              "0x68db8bac710cb4000000000000000",
              "0xc8",
              "0x0",
              "0x332bdbc767000276a4e6b4939a"
            ]
          }
        ],
        "amountToApprove": "10000000",
        "gasCostUSD": "",
        "fromChainId": "SN_MAINNET(custom chainId 4012)",
        "fromAmountUSD": "9.949725",
        "fromAmount": "10000000",
        "fromToken": {
          "address": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
          "symbol": "USDC",
          "decimals": 6
        },
        "fromAddress": "0x0309e6b209031362268d62d646a067365e6f6d6eb7f571b5212cbdfd5f26fe54",
        "toChainId": "SN_MAINNET(custom chainId 4012)",
        "toAmountUSD": "9.987543",
        "toAmount": "2547452702672063",
        "toToken": {
          "address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
          "symbol": "ETH",
          "decimals": 18
        },
        "toAddress": "0x4270219d365d6b017231b52e92b3fb5d7c8378b05e9abc97724537a80e93b0f",
        "receiver": "0x0309e6b209031362268d62d646a067365e6f6d6eb7f571b5212cbdfd5f26fe54"
      },
      "extractedParams": {
        "action": "swap",
        "chain": "starknet",
        "token1": "usdc",
        "token2": "eth",
        "address": "",
        "amount": "10"
      },
      "conversationHistory": [
        {
          "sender": "user",
          "content": "swap 10 usdc to eth on starknet"
        },
        {
          "sender": "brian",
          "content": "You are about to swap 10.0 USDC ($9.9) for 0.0025 ETH ($10.0) on Starknet using Avnu.fi solver. The address receiver is 0x0309e6b209031362268d62d646a067365e6f6d6eb7f571b5212cbdfd5f26fe54."
        }
      ]
    }
  ]
}

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"
Response
{
  "result": [
    {
      "solver": "Brian-Solana",
      "action": "transfer",
      "type": "write",
      "data": {
        "description": "You are about to transfer 2 sol to CnXMWB8W7bcnADsZsJAJYkcuu8jr392ZFvxDBiumW3ww on Solana.",
        "steps": [
          {
            "data": "gAEAAQM8LZeA9qBvRbVQG5heYfyIuwarnP0Gu9tInqEHyOcgla8aA27cGkJPxlgCjOuAxr2EFf+HIngbWdjMb4lANG/CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACTDmG4RDbxk5rt25m9qiHclTvVxLZxbKeDyW+6AW0SSAECAgABDAIAAABAQg8AAAAAAAA="
          }
        ],
        "fromChainId": 1151111081099710,
        "fromAmount": "2000000000",
        "fromTokenSymbol": "sol",
        "fromToken": "11111111111111111111111111111111",
        "fromAddress": "53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr",
        "toChainId": 1151111081099710,
        "toAmount": "2000000000",
        "toAmountMin": "2000000000",
        "toToken": "11111111111111111111111111111111",
        "toTokenSymbol": "sol",
        "toAddress": "11111111111111111111111111111111",
        "receiver": "CnXMWB8W7bcnADsZsJAJYkcuu8jr392ZFvxDBiumW3ww"
      },
      "extractedParams": {
        "action": "transfer",
        "token1": "sol",
        "chain": "solana",
        "address": "CnXMWB8W7bcnADsZsJAJYkcuu8jr392ZFvxDBiumW3ww",
        "amount": "2"
      },
      "conversationHistory": [
        {
          "sender": "user",
          "content": "transfer 2 sol to CnXMWB8W7bcnADsZsJAJYkcuu8jr392ZFvxDBiumW3ww on solana"
        },
        {
          "sender": "brian",
          "content": "You are about to transfer 2 sol to CnXMWB8W7bcnADsZsJAJYkcuu8jr392ZFvxDBiumW3ww on Solana."
        }
      ]
    }
  ]
}

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"
Response
{
  "result": [
    {
      "solver": "Jupiter",
      "action": "swap",
      "type": "write",
      "data": {
        "description": "You are about to swap 2000000000 sol for 427998127 usdc on [object Object] using Jupiter solver. The address receiver is 53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr.",
        "steps": [
          {
            "data": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAGCTwtl4D2oG9FtVAbmF5h/Ii7Bquc/Qa720ieoQfI5yCVuyTAY0LGzNW3JsUn1WCmzitgoSRt4O5DFQ4mohw/AsvDuizr7JweMPVk7RuLPfzrfj9yS9TUC6qnDZt0jVJpCQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAAEedVb8jHAbu50xW7OaBUH/bGy3qP0jlECsc2iVrwTjwbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04kifG7PRApFI4NgwtaE5na/xCEBI572Nvp+Fm0P/on9df2SnTAmx8pWHneSwmrNt/J3VFLMhqns4zl6AaGHcvh7tvPVuJirOhrdz0uo/2pa9nVljQ7Ch7anDl2BwQABQLAXBUABAAJAwQXAQAAAAAABwYAAgAOAwYBAQMCAAIMAgAAAACUNXcAAAAABgECAREFFwYAAgEFEwUIBRAPDQACAQwJCgsGERESI+UXy5d6460qAQAAABlkAAEAlDV3AAAAAK+7ghkAAAAAMgAABgMCAAABCQHaPXgX4+NThv0V83XX6UI4/kChgKeZEox3sbxohfBHHwVSS0xRTgYaSlBNTzg="
          }
        ],
        "fromChainId": 1151111081099710,
        "fromAmount": "2000000000",
        "fromTokenSymbol": "sol",
        "fromToken": "So11111111111111111111111111111111111111112",
        "fromAddress": "53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr",
        "toChainId": 1151111081099710,
        "toAmount": "427998127",
        "toAmountMin": "427998127",
        "toToken": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        "toTokenSymbol": "usdc",
        "toAddress": [
          "Gkt4BpMRFxhhrrVMQsewM74ggriAbxyN2yUYDD9qt1NV"
        ],
        "receiver": "53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr"
      },
      "extractedParams": {
        "action": "swap",
        "chain": "solana",
        "token1": "sol",
        "token2": "usdc",
        "address": "",
        "amount": "2"
      },
      "conversationHistory": [
        {
          "sender": "user",
          "content": "swap 2 sol to usdc on solana"
        },
        {
          "sender": "brian",
          "content": "You are about to swap 2000000000 sol for 427998127 usdc on [object Object] using Jupiter solver. The address receiver is 53unSgGWqEWANcPYRF35B2Bgf8BkszUtcccKiXwGGLyr."
        }
      ]
    }
  ]
}

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