Wallet
Why does an agent need a Wallet?
To enable an agent to interact with the blockchain—such as autonomously executing trades—you must create a wallet and grant the agent control access. This allows the agent to sign transactions, for example, swapping assets based on its financial decisions.
Wallet Setup
Before using the wallet, you must either
- create a new Solana wallet
- or import an existing wallet
Creating a Wallet
Use the following command to create a new wallet:
By default, the wallet’s private key is stored at ~/secret/.private_key.json
. You can specify a custom path using the --path
flag:
The private key is stored in JSON format as a standard Solana Ed25519 keypair.
Importing an Existing Wallet
To import an existing wallet, use one of the following methods:
Import from a file
Import using a private key string
After importing or creating a wallet, it will be ready for use. The private key’s storage path can be found under SOLANA_PRIVATE_KEY_PATH
in .agents.env
.
Using a Wallet in an Agent
Prerequisites
Important: Ensure your wallet is funded before use. Without sufficient SOL, Web3 tools may fail due to a lack of gas fees or available funds.
Agent Code Example
Once the wallet is set up, it is automatically accessible by Web3 tools. To use it, simply include Web3 tools in your agent’s toolset.
Below is an example of how to enable the agent with the Jupiter tool for token swapping. The agent can call the swap_token
function using the previously set up wallet to execute swaps when needed.
For details on tool integration, refer to the tools section of the documentation.