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:

galadriel wallet create

By default, the wallet’s private key is stored at ~/secret/.private_key.json. You can specify a custom path using the --path flag:

galadriel wallet create --path /your/custom/path.json

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

galadriel wallet import --path /Users/galadriel/my_solana_key.json

Import using a private key string

galadriel wallet import --private-key "[236,183,172,159,151,136,98,48,88,225,87,94,91,65,98,19,19,145,171,156,142,193,63,132,224,192,216,112,222,61,41,9,226,41,148,80,123,104,2,9,100,141,69,233,137,201,64,43,166,147,184,64,70,212,61,187,36,92,170,120,136,163,236,231]"

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.

agent = CodeAgent(
    model=model,
    tools=[jupiter.swap_token],
)

For details on tool integration, refer to the tools section of the documentation.