Learn to Code with Ai
Learn how to code with AI. Step through interactive tutorials that turn plain-language instructions into working Solana code. Carbium’s AI-ready documentation helps you move from idea to deployment through guided, reproducible examples.
Communicating with AI
Before writing code, it’s essential to understand how to talk to an AI assistant effectively. AI models understand structured language, clarity and context improve their accuracy.
Best practices:
- Be explicit: specify which language (Rust, TypeScript, Python, etc.) or framework you’re using.
- Python is easy-to-approach and powerful for DeFi activities.
- Include details about the environment (Solana SDK, CLI tools, RPC endpoint).
- Request step-by-step output or ask the AI to explain what each part of the code does.
- Iterate: if a response is incomplete, refine your prompt rather than restarting.
Example prompt:
“Write a Python script that trades SOL for USDC using the Carbium DEX API endpoint and logs transaction signatures.”
Supported AI Assistants
You can use any LLM interface capable of structured code generation. Every major artifical intelligence does have Code intepreter features:
- OpenAI GPT models (GPT-5, Especially Codex)
- Anthropic Claude
- Perplexity, Gemini, or local LLMs
To get the best results, share the Carbium documentation link with your assistant, otherwise you can share snippets from our documentation:
https://docs.carbium.io
This allows the model to reference Carbium’s official endpoints, syntax, and RPC structure.
Integrating AI via CLI or Editor
You can directly integrate GPT into your coding workflow using the OpenAI CLI or Visual Studio Code extensions.
Option A – Using the OpenAI CLI
You’ll need an OpenAI API key and the openai command-line interface installed.
Installation
pip install openaiAuthenticate
export OPENAI_API_KEY="your_api_key_here"Example Usage
openai api.chat_completions.create \
-m gpt-4-turbo \
-g "Generate a Rust function that initializes a Solana account with Carbium RPC"See the official OpenAI reference for all CLI flags: ➡ OpenAI CLI documentation
Option B – Using Visual Studio Code
- Install the ChatGPT Codex CLI or Claude Code integration
- Add your API key in the settings.
- You can then query GPT directly in the sidebar or inline editor.
- Paste snippets from Carbium docs
Option C – Using Apple Terminal with GPT or Claude
If you prefer working natively on macOS, you can run both OpenAI GPT and Anthropic Claude models directly from the Apple Terminal. This approach is ideal for quick code generation, prototyping, or integrating Carbium’s SDK commands without switching editors.
1. Set Up the Environment
Ensure that Python 3 and pip are installed on your system.
Then install the official OpenAI and Anthropic Python clients:
pip install openai anthropicSet your API keys as environment variables:
export OPENAI_API_KEY="your_openai_api_key"
export ANTHROPIC_API_KEY="your_anthropic_api_key"(You can add these lines to ~/.zshrc or ~/.bash_profile to make them permanent.)
2. Run GPT from the Terminal
Generate code directly through the OpenAI Python client:
python3 - <<'PY'
from openai import OpenAI
client = OpenAI()
prompt = "Generate a Python script that queries Carbium RPC and prints the latest Solana slot number."
resp = client.chat.completions.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": prompt}]
)
print(resp.choices[0].message.content)
PY3. Run Claude from the Terminal
Use Anthropic’s client for Claude 3 Opus or Claude Instant:
python3 - <<'PY'
from anthropic import Anthropic
client = Anthropic()
prompt = "Write a Rust example that initializes a Solana wallet using Carbium SDK."
resp = client.messages.create(
model="claude-3-opus-20240229",
max_tokens=500,
messages=[{"role": "user", "content": prompt}]
)
print(resp.content[0].text)
PY4. Combine with Carbium Docs
Reference the Carbium documentation directly in your prompt to ensure the AI uses official APIs and syntax:
Reference docs: https://docs.carbium.io
Task: Generate a Solana transaction using Carbium’s DEX API.This improves accuracy and guarantees compatibility with Carbium’s RPC and SDK layers.
Technical References
- OpenAI CLI and API Reference: https://help.openai.com/en/articles/11096431-openai-codex-cli-getting-started
- Anthropic Claude Code CLI Reference: https://docs.anthropic.com/en/docs/claude-code/cli-reference
- Anthropic Quick Start for CLI: https://docs.anthropic.com/en/docs/claude-code/quickstart
5. Next Steps
Once you’re comfortable communicating with AI, continue to:
Updated about 9 hours ago
