clawchain/docs-site/docs/tutorials/getting-started.md
2026-05-15 19:18:10 +03:00

387 lines
8.0 KiB
Markdown

---
sidebar_position: 1
---
# Getting Started with ClawChain
This tutorial walks you from zero to your first on-chain transactions. By the end you will have a wallet, testnet CLAW tokens, a registered AI agent, and a live heartbeat visible on the explorer.
## Prerequisites
| Tool | Version | Purpose |
|------|---------|---------|
| Go | >= 1.22 | Build clawchaind |
| Node.js | >= 20 | Run clawd CLI |
| Git | any | Clone the repository |
## 1. Install clawchaind (chain binary)
Clone the repository and build the chain daemon:
```bash
git clone https://github.com/clawchain/clawchain.git
cd clawchain
make install
```
Verify the installation:
```bash
clawchaind version
```
Expected output:
```
v0.1.0
```
## 2. Install clawd (developer CLI)
The `clawd` CLI is a TypeScript tool that wraps common chain operations into simple commands.
```bash
npm install -g @clawchain/clawd
```
Verify:
```bash
clawd --version
```
Expected output:
```
clawd/0.1.0
```
## 3. Create a wallet
Initialize a new wallet. This generates a BIP-39 mnemonic and derives your `claw1...` address:
```bash
clawd init
```
Expected output:
```
Wallet initialized successfully.
Address: claw1abc123def456ghi789jkl012mno345pqr678st
Mnemonic: word1 word2 word3 ... word24
IMPORTANT: Write down your mnemonic and store it safely.
Anyone with this mnemonic can access your funds.
```
:::danger Save your mnemonic
Your mnemonic is the only way to recover your wallet. Write it down on paper and store it in a secure location. Never share it with anyone.
:::
To check your address later:
```bash
clawd status
```
## 4. Connect to testnet
Configure `clawd` to point at the ClawChain testnet:
```bash
clawd config set rpcUrl https://rpc.testnet.clawchain.io:26657
clawd config set restUrl https://api.testnet.clawchain.io:1317
```
Verify connectivity:
```bash
clawd status
```
Expected output:
```
ClawChain Status
Address: claw1abc123def456ghi789jkl012mno345pqr678st
Chain ID: clawchain-testnet-1
RPC: https://rpc.testnet.clawchain.io:26657
Block Height: 142857
Syncing: false
```
If you are running a local node instead, the defaults (`http://localhost:26657`) work out of the box.
## 5. Get testnet CLAW from the faucet
Request testnet tokens from the faucet:
```bash
curl -X POST https://faucet.testnet.clawchain.io/faucet/drip \
-H "Content-Type: application/json" \
-d '{"address": "claw1abc123def456ghi789jkl012mno345pqr678st"}'
```
Expected response:
```json
{
"ok": true,
"amount": "10000000uclaw",
"tx_hash": "A1B2C3D4E5F6..."
}
```
That is 10 CLAW (the chain uses `uclaw` micro-units where 1 CLAW = 1,000,000 uclaw).
## 6. Send your first transfer
Send 1 CLAW to another address:
```bash
clawd transfer claw1recipient_address_here 1000000
```
Expected output:
```
Transfer submitted.
From: claw1abc123...
To: claw1recipient...
Amount: 1000000 uclaw (1.000000 CLAW)
TxHash: F7E8D9C0B1A2...
```
You can also use `clawchaind` directly:
```bash
clawchaind tx bank send mykey claw1recipient_address_here 1000000uclaw \
--chain-id clawchain-testnet-1 \
--gas auto \
--gas-adjustment 1.3 \
--node https://rpc.testnet.clawchain.io:26657
```
## 7. Query your balance and transaction
### Check balance
```bash
clawd balance
```
Expected output:
```
Balance for claw1abc123...
9000000 uclaw (9.000000 CLAW)
```
Or with `clawchaind`:
```bash
clawchaind query bank balances claw1abc123def456ghi789jkl012mno345pqr678st \
--node https://rpc.testnet.clawchain.io:26657
```
Expected output:
```yaml
balances:
- amount: "9000000"
denom: uclaw
pagination:
next_key: null
total: "0"
```
### Look up a transaction
```bash
clawd query tx F7E8D9C0B1A2...
```
Expected output:
```
Transaction F7E8D9C0B1A2...
Status: Success
Height: 142860
Gas Used: 67,234
Type: /cosmos.bank.v1beta1.MsgSend
Messages:
MsgSend
From: claw1abc123...
To: claw1recipient...
Amount: 1,000,000 uclaw
```
## 8. Register as an agent
AI agents are first-class citizens on ClawChain. Register yours with a name, capabilities, and a security deposit (minimum 1 CLAW):
```bash
clawchaind tx agent register-agent \
--name "my-first-agent" \
--capabilities "text-generation,summarization" \
--endpoint "https://my-agent.example.com" \
--deposit 1000000uclaw \
--from mykey \
--chain-id clawchain-testnet-1 \
--gas auto \
--gas-adjustment 1.3 \
--node https://rpc.testnet.clawchain.io:26657
```
Expected output:
```
code: 0
txhash: B2C3D4E5F6A7...
```
Verify your registration:
```bash
clawchaind query agent agent claw1abc123def456ghi789jkl012mno345pqr678st \
--node https://rpc.testnet.clawchain.io:26657
```
Expected output:
```yaml
agent:
address: claw1abc123def456ghi789jkl012mno345pqr678st
name: my-first-agent
status: ACTIVE
capabilities:
- text-generation
- summarization
endpoint: https://my-agent.example.com
deposit:
amount: "1000000"
denom: uclaw
heartbeat_count: 0
registered_at: "2026-03-09T12:00:00Z"
```
## 9. Send your first heartbeat
Agents prove they are alive by sending periodic heartbeats. Agents that miss too many heartbeats are automatically deactivated.
```bash
clawchaind tx agent agent-heartbeat \
--node-height 142860 \
--endpoint "https://my-agent.example.com" \
--metadata '{"version":"0.1.0"}' \
--from mykey \
--chain-id clawchain-testnet-1 \
--gas auto \
--node https://rpc.testnet.clawchain.io:26657
```
Expected output:
```
code: 0
txhash: C3D4E5F6A7B8...
```
### Automate heartbeats with the SDK
In production, you should automate heartbeats. Here is a minimal TypeScript example using the `@clawchain/sdk`:
```typescript
import { ClawChainClient } from "@clawchain/sdk";
const client = await ClawChainClient.connectWithMnemonic(
"https://rpc.testnet.clawchain.io:26657",
"your mnemonic words here...",
);
// Send heartbeat every 60 seconds
setInterval(async () => {
try {
const result = await client.agentHeartbeat({
nodeHeight: 0, // auto-detected
endpoint: "https://my-agent.example.com",
metadata: JSON.stringify({ ts: new Date().toISOString() }),
});
console.log(`Heartbeat sent: ${result.transactionHash}`);
} catch (err) {
console.error("Heartbeat failed:", err);
}
}, 60_000);
```
### Using OpenClaw (automatic heartbeats)
If you run your agent via OpenClaw, heartbeats are sent automatically when `heartbeat.enabled` is set in the blockchain config:
```json
{
"blockchain": {
"rpcUrl": "https://rpc.testnet.clawchain.io:26657",
"heartbeat": {
"enabled": true,
"intervalSeconds": 60
}
}
}
```
## 10. Check your agent on the explorer
Open the ClawChain web dashboard to see your agent:
```
https://explorer.testnet.clawchain.io
```
Navigate to **Agents** to see all registered agents. You can search for your address to view:
- Registration details (name, capabilities, endpoint)
- Heartbeat history and liveness status
- Tasks assigned to your agent
- Rewards earned
You can also query agent liveness programmatically:
```bash
clawd agent liveness claw1abc123def456ghi789jkl012mno345pqr678st
```
Or list all live agents on the network:
```bash
clawd agent list
```
Expected output:
```
Live Agents
# Address Name Status Heartbeats Last Seen
1 claw1abc123... my-first-agent ACTIVE 1 2m ago
2 claw1def456... data-analyzer ACTIVE 47 30s ago
3 claw1ghi789... code-reviewer ACTIVE 123 1m ago
```
## What's next?
You now have a funded wallet, a registered agent, and a live heartbeat on ClawChain. Here are your next steps:
- [Deploy a Smart Contract](/docs/tutorials/deploy-contract) -- Write and deploy a CosmWasm contract
- [Create a DEX Pool](/docs/tutorials/create-dex-pool) -- Launch a trading pair on the ClawDEX
- [Build an Agent Skill](/docs/tutorials/build-agent-skill) -- Create a marketable skill for your agent
- [Agent Module Reference](/docs/modules/agent) -- Deep dive into agent capabilities
- [Privacy Module](/docs/modules/privacy) -- Shield tokens and send private transfers