SolanaAccount
A class representing a Solana account managed by the CDP API.
Constructor
SolanaAccount(
solana_account_model: SolanaAccountModel,
api_clients: ApiClients,
)
This constructor is typically not called directly. Use CdpClient.solana.create_account() instead.
Properties
address
@property
def address(self) -> str:
Get the address of the Solana account.
The address of the Solana account (Base58-encoded string).
name
@property
def name(self) -> str | None:
Get the name of the Solana account.
The name of the Solana account, or None if not set.
policies
@property
def policies(self) -> list[str]:
Get the list of policies that apply to this account.
Methods
request_faucet
async def request_faucet(
self,
token: Literal["sol", "usdc"],
) -> RequestSolanaFaucetResponse:
Request a faucet for the Solana account.
token
Literal['sol', 'usdc']
required
The token to request the faucet for. Must be either “sol” or “usdc”.
return
RequestSolanaFaucetResponse
The response from the faucet.
# Example: Request SOL from faucet
response = await account.request_faucet(token="sol")
sign_message
async def sign_message(
self,
message: str,
idempotency_key: str | None = None,
) -> SignSolanaMessageResponse:
Sign a message.
The optional idempotency key for safe retryable requests.
return
SignSolanaMessageResponse
The signature of the message.
# Example: Sign a message
signature = await account.sign_message(
message="Hello, Solana!",
idempotency_key="unique-key-123",
)
sign_transaction
async def sign_transaction(
self,
transaction: str,
idempotency_key: str | None = None,
) -> SignSolanaTransactionResponse:
Sign a transaction.
The transaction to sign (Base58-encoded string).
The optional idempotency key for safe retryable requests.
return
SignSolanaTransactionResponse
The signature of the transaction.
# Example: Sign a transaction
signed = await account.sign_transaction(
transaction="base58_encoded_transaction",
)
transfer
async def transfer(
self,
to: str,
amount: int,
token: str,
network: str,
) -> str:
Transfer a token from the Solana account to a destination address.
The destination address to transfer the token to (Base58-encoded Solana address).
The amount to transfer in atomic units of the token. For example, 0.01 * LAMPORTS_PER_SOL would transfer 0.01 SOL.
The token to transfer (e.g., “sol”, “usdc”).
The network to transfer the token on (e.g., “solana-devnet”, “solana”).
The signature of the transaction.
# Example: Transfer SOL
from solders.system_program import LAMPORTS_PER_SOL
signature = await account.transfer(
to="destination_address_base58",
amount=int(0.01 * LAMPORTS_PER_SOL), # 0.01 SOL
token="sol",
network="solana-devnet",
)
Example Usage
Create and Use a Solana Account
from cdp import CdpClient
async with CdpClient(
api_key_id="your-api-key-id",
api_key_secret="your-api-key-secret",
) as cdp:
# Create a Solana account
account = await cdp.solana.create_account(name="My Solana Account")
print(f"Solana address: {account.address}")
# Request SOL from faucet (testnet only)
faucet_response = await account.request_faucet(token="sol")
print(f"Faucet transaction: {faucet_response}")
# Transfer SOL to another address
from solders.system_program import LAMPORTS_PER_SOL
signature = await account.transfer(
to="destination_address",
amount=int(0.1 * LAMPORTS_PER_SOL),
token="sol",
network="solana-devnet",
)
print(f"Transfer signature: {signature}")