Automatically generates comprehensive API documentation from Anchor IDL files with instruction signatures, account layouts, error codes, and usage examples
curl -s https://parity.cx/api/skills/idl-docs | shcopyYou are generating comprehensive API documentation from an Anchor program's IDL (Interface Description Language). The IDL is the canonical interface contract between the on-chain program and its clients. The documentation must be complete enough for a frontend developer to integrate with the program without reading the Rust source.
| Source | Path | Contains |
|--------|------|----------|
| Framework Patterns | programs/parity/src/context_engine.rs > ANCHOR_PATTERNS | Anchor account patterns to explain in documentation context |
| Best Practices Skill | skills/best-practices/SKILL.md | Convention checks including error message quality and event documentation |
GitHub base URL: https://github.com/paritydotcx/Skills/blob/main/
If the input is a .json IDL file, parse it directly. If the input is a .rs source file, extract the interface by analyzing:
#[program] module — instruction handler signatures#[derive(Accounts)] structs — account inputs per instruction#[account] structs — stored account layouts with field types and sizes#[error_code] enum — error codes with messages#[event] structs — emitted events with field typesBuild a structured representation of the program interface.
Generate a header section:
# Program Name
**Program ID:** `YOUR_PROGRAM_ID`
**Framework:** Anchor vX.X.X
**Instructions:** N
**Account Types:** N
**Events:** N
**Errors:** NInclude a table of contents linking to each instruction, account type, event, and error.
For each instruction, generate:
Description: Inferred from handler logic and parameter names.
Parameters:
| Name | Type | Description |
|------|------|-------------|
| amount | u64 | Amount of tokens to deposit |
Accounts:
| Name | Type | Mutable | Signer | Description |
|------|------|---------|--------|-------------|
| vault | Account\<Vault\> | Yes | No | PDA-derived vault account |
| authority | Signer | No | Yes | Transaction signer and vault owner |
| system_program | Program\<System\> | No | No | Solana System Program |
PDA Seeds (if any accounts are PDA-derived):
vault: ["vault", authority.key()]Errors that may be thrown:
InvalidAmount — Amount must be greater than zeroOverflow — Arithmetic overflow in balance calculationEvents emitted:
DepositEvent — Emitted on successful deposit with amount and new balanceTypeScript Example (if include_examples is true):
await program.methods
.deposit(new anchor.BN(1_000_000))
.accounts({
vault: vaultPda,
authority: wallet.publicKey,
systemProgram: SystemProgram.programId,
})
.rpc();For each #[account] type:
Space: 8 (discriminator) + N bytes
| Field | Type | Size | Description |
|-------|------|------|-------------|
| authority | Pubkey | 32 | Account owner |
| balance | u64 | 8 | Current token balance |
| bump | u8 | 1 | PDA canonical bump |
Fetch Example:
const vault = await program.account.vault.fetch(vaultPda);
console.log("Balance:", vault.balance.toNumber());Derivation (if PDA):
const [vaultPda] = PublicKey.findProgramAddressSync(
[Buffer.from("vault"), authority.toBuffer()],
programId
);For each #[event]:
| Field | Type | Description |
|-------|------|-------------|
| authority | Pubkey | Signer who initiated the action |
| amount | u64 | Amount transferred |
Listener Example:
const listener = program.addEventListener("DepositEvent", (event, slot) => {
console.log("Deposit:", event.amount.toNumber(), "at slot", slot);
});Table of all error codes:
| Code | Name | Message |
|------|------|---------|
| 6000 | InvalidAmount | Amount must be greater than zero |
| 6001 | Overflow | Arithmetic overflow in balance calculation |
| 6002 | InsufficientBalance | Withdrawal exceeds available balance |
Error Handling Example:
try {
await program.methods.deposit(new anchor.BN(0)).accounts({...}).rpc();
} catch (err) {
if (err.error.errorCode.code === "InvalidAmount") {
console.error("Deposit amount must be positive");
}
}Generate TypeScript interfaces matching the IDL:
export interface Vault {
authority: PublicKey;
balance: BN;
isActive: boolean;
bump: number;
}
export interface DepositEvent {
authority: PublicKey;
vault: PublicKey;
amount: BN;
newBalance: BN;
}Return the complete documentation as a single markdown document (or HTML/JSON depending on format input). The document must be self-contained and include all examples, type definitions, and integration guidance.
{
"documentation": "# Program Name\n\n...",
"type_definitions": "export interface Vault { ... }"
}