Developer Portal

Build on Key

Open protocol, infinite possibilities

Quick Start

Option 1: Use Key API

Quickest way to get started. Use our API for username registration, message sending, and inbox fetching.

No blockchain knowledge required

Option 2: Direct Program Calls

Maximum control. Call the Solana program directly, implement your own fee-payer, build custom infrastructure.

Full customization, no dependencies

API Reference

Base URL:

https://api.trykey.app

All requests require the following headers:

Content-Type: application/json
X-API-Key: YOUR_API_KEY
POST /api/username/register

Register a new username on-chain

// Request Body
{
  "username": "alice",
  "publicKey": "Fkf3...base58",
  "encryptionKey": "Ab4d...base64",
  "signature": "YzNm...base64",
  "timestamp": 1704067200000
}
POST /api/message/send

Send encrypted message to recipient

// Request Body
{
  "encryptedMessage": "base64_ciphertext",
  "recipientPubkey": "Fkf3...base58",
  "senderPubkey": "Ab4d...base58",
  "signature": "YzNm...base64",
  "timestamp": 1704067200000
}
GET /api/message/inbox/:pubkey

Fetch received messages

// Response
{
  "messages": [
    {
      "signature": "tx_sig",
      "senderPubkey": "Fkf3...base58",
      "encryptedMessage": "base64_ciphertext",
      "timestamp": 1704067200
    }
  ]
}
POST /api/groups/create

Create a new group chat

// Request Body
{
  "name": "My Group",
  "maxMembers": 50,
  "creatorPubkey": "Ab4d...base58",
  "signature": "YzNm...base64",
  "timestamp": 1704067200000
}
POST /api/message/group/:id/send

Send encrypted message to group

// Request Body
{
  "encryptedMessage": "base64_ciphertext",
  "encryptedKeys": {
    "member1_pubkey": "encrypted_key_1",
    "member2_pubkey": "encrypted_key_2"
  },
  "senderPubkey": "Ab4d...base58",
  "signature": "YzNm...base64",
  "timestamp": 1704067200000
}

API Key

To use the Key API, include your API key in the X-API-Key header.

Request Example:

fetch('https://api.trykey.app/api/message/inbox/PUBKEY', {
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your_api_key_here'
  }
});

Contact us at dev@trykey.app to obtain your API key for production use.

Program Interface (IDL)

Program Address:

96hG67JxhNEptr1LkdtDcrqvtWiHH3x4GibDBcdh4MYQ

registerUsername

Create a new username account (PDA derived from username)

pub fn register_username(
  ctx: Context<RegisterUsername>,
  username: String,
  encryption_key: [u8; 32]
) -> Result<()>

updateEncryptionKey

Rotate encryption key (owner-only)

pub fn update_encryption_key(
  ctx: Context<UpdateEncryptionKey>,
  new_key: [u8; 32]
) -> Result<()>

transferUsername

Transfer username to new owner

pub fn transfer_username(
  ctx: Context<TransferUsername>,
  new_owner: Pubkey
) -> Result<()>

Code Examples

TypeScript (Client)

// Encrypt a message with TweetNaCl
import nacl from 'tweetnacl';
import bs58 from 'bs58';
const nonce = nacl.randomBytes(nacl.box.nonceLength);
const messageBytes = new TextEncoder().encode(message);
const encrypted = nacl.box(
  messageBytes,
  nonce,
  recipientPublicKey,
  senderSecretKey
);

Rust (Program)

// Username account structure
#[account]
pub struct UserAccount {
    pub owner: Pubkey,
    pub username: String,
    pub encryption_key: [u8; 32],
    pub created_at: i64,
    pub bump: u8,
}

SDKs & Libraries

JavaScript/TypeScript

  • • @solana/web3.js
  • • tweetnacl
  • • bs58
  • • @coral-xyz/anchor

Rust

  • • anchor-lang
  • • solana-program
  • • borsh
  • • ed25519-dalek

Python

  • • solana-py
  • • PyNaCl
  • • base58

Community