|
| 1 | +import {OpenApiEndpoint} from "@doc"; |
| 2 | + |
| 3 | +# Transaction Execution |
| 4 | + |
| 5 | +thirdweb AI can either auto execute transactions or prepare them for signing. |
| 6 | + |
| 7 | +- **Auto Execute**: The API will auto execute the transaction. Requires wallet authentication. |
| 8 | +- **Prepare for Signing**: The API will only prepare the transaction for signing. The user will need to sign the transaction manually. |
| 9 | + |
| 10 | +## Auto Execute |
| 11 | + |
| 12 | +Requirements: |
| 13 | + |
| 14 | +- The context object must be set with: |
| 15 | + - `from` set to the wallet address to execute the transaction from |
| 16 | + - `auto_execute_transaction` set to `true` |
| 17 | + - (Optional) `chain_ids` set to the chain IDs to execute the transaction on |
| 18 | +- The API must be called with either: |
| 19 | + - your `x-secret-key` header for server wallet authentication |
| 20 | + - OR a `Authorization` header with a valid wallet JWT for user wallet authentication |
| 21 | + |
| 22 | +Model behavior: |
| 23 | + |
| 24 | +If all the requirements are met, the transaction will be executed automatically and the model will return a message with the transaction ID. |
| 25 | + |
| 26 | +It will also include an `actions` array with a `monitor_transaction` action. This action can be used to monitor the transaction status and get the transaction receipt via the thirdweb API. |
| 27 | + |
| 28 | +<OpenApiEndpoint path="/ai/chat" method="POST" requestBodyOverride={{ |
| 29 | + "messages": [ |
| 30 | + { |
| 31 | + "role": "user", |
| 32 | + "content": "Transfer 10 USDC to vitalik.eth" |
| 33 | + } |
| 34 | + ], |
| 35 | + "context": { |
| 36 | + "from": "0x...", |
| 37 | + "auto_execute_transaction": true, |
| 38 | + "chain_ids": [8453] |
| 39 | + } |
| 40 | +}} responseExampleOverride={{ |
| 41 | + "message": "I've sent 10 USDC to Vitalik's wallet with transaction ID 11cd95e3-c0ee-4468-97c1-fd05dc919cdb. It should be confirmed in a few seconds.", |
| 42 | + "session_id": "123", |
| 43 | + "request_id": "456", |
| 44 | + "actions": [{ |
| 45 | + "session_id": "8d1bfac4-e6c0-473b-bbb6-649f459d37e6", |
| 46 | + "request_id": "79066871-b86f-4814-8027-5f34d99df389", |
| 47 | + "source": "model", |
| 48 | + "type": "monitor_transaction", |
| 49 | + "data": { |
| 50 | + "transaction_id": "11cd95e3-c0ee-4468-97c1-fd05dc919cdb" |
| 51 | + } |
| 52 | +}] |
| 53 | +}} /> |
| 54 | + |
| 55 | +## Prepare for Signing |
| 56 | + |
| 57 | +When the `auto_execute` parameter is set to `false` or omitted, the API will prepare the transaction for signing and return the transaction data in the `actions` array as a 'sign_transaction' action type. |
| 58 | + |
| 59 | +<OpenApiEndpoint path="/ai/chat" method="POST" /> |
0 commit comments