Skip to main content
This guide walks through the core Protochain workflow in five minutes. By the end, you’ll have a funded devnet keypair and have made successful API calls to the Account Service. All examples use the Account Service — the same connection pattern applies to every other Protochain service.
1

Connect to the Protochain server

Before making any API calls, create a gRPC channel and instantiate the Account Service client. See Connecting to Protochain for full TLS/credential options and endpoint configuration.
package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials/insecure"
    account_v1 "github.com/meshtrade/protochain/lib/go/protochain/solana/account/v1"
)

func main() {
    conn, err := grpc.NewClient("YOUR_ENDPOINT:50051",
        grpc.WithTransportCredentials(insecure.NewCredentials()),
    )
    if err != nil {
        log.Fatalf("connect: %v", err)
    }
    defer conn.Close()

    client := account_v1.NewServiceClient(conn)
    ctx := context.Background()
    // continue below...
}
2

Fetch an existing account

Call GetAccount with any known Solana address. This confirms your connection is working and returns the account’s SOL balance and owner program.
resp, err := client.GetAccount(ctx, &account_v1.GetAccountRequest{
    Address: "11111111111111111111111111111111",
})
if err != nil {
    log.Fatalf("GetAccount: %v", err)
}
fmt.Printf("address: %s\n", resp.Account.Address)
fmt.Printf("lamports: %d\n", resp.Account.Lamports)
fmt.Printf("owner: %s\n", resp.Account.Owner)
fmt.Printf("executable: %v\n", resp.Account.Executable)
The System Program account (11111111111111111111111111111111) is always present on all Solana networks. Fetching it is a reliable connectivity test.
3

Generate a new keypair

Generate a fresh keypair to use as your dev account. The private key is returned in plaintext — store it securely.
The private key returned by GenerateNewKeyPair is in plaintext. Never commit it to source control or transmit it outside a secure context. For production use, generate keys offline and never pass them through a server.
kpResp, err := client.GenerateNewKeyPair(ctx, &account_v1.GenerateNewKeyPairRequest{})
if err != nil {
    log.Fatalf("GenerateNewKeyPair: %v", err)
}
fmt.Printf("public key:  %s\n", kpResp.KeyPair.PublicKey)
fmt.Printf("private key: %s\n", kpResp.KeyPair.PrivateKey)
4

Fund your keypair on devnet

FundNative uses the Solana devnet faucet. It only works on devnet — it will fail on mainnet or testnet. This is intentional: real SOL cannot be airdropped.
Fund the keypair you just generated with 1 SOL (1,000,000,000 lamports) from the devnet faucet. Then fetch the account to confirm the balance.
// publicKey is the public key from Step 3
fundResp, err := client.FundNative(ctx, &account_v1.FundNativeRequest{
    Address: publicKey,
    Amount:  "1000000000", // 1 SOL in lamports
})
if err != nil {
    log.Fatalf("FundNative: %v", err)
}
fmt.Printf("airdrop signature: %s\n", fundResp.Signature)

// Verify the balance
acctResp, err := client.GetAccount(ctx, &account_v1.GetAccountRequest{
    Address: publicKey,
})
if err != nil {
    log.Fatalf("GetAccount: %v", err)
}
fmt.Printf("balance: %d lamports\n", acctResp.Account.Lamports)

Next steps

You now have a working Protochain connection and a funded devnet keypair. From here: