SDK Reference
Install and use IntentRail SDKs for TypeScript, Rust, and Python.
TypeScript
@intentrail/sdk
npm install @intentrail/sdk1{{KEYWORD:import}} {2 createIntent,3 signIntent,4 verifyIntent,5 summarizeIntent,6 SOL_MINT,7} {{KEYWORD:from}} {{STRING:"@intentrail/sdk"}};89{{COMMENT:// Create an intent}}10{{KEYWORD:const}} intent = createIntent({11 expires_at: {{KEYWORD:new}} Date(Date.now() + 15 * 60 * 1000).toISOString(),12 network: {{STRING:"mainnet-beta"}},13 action: {{STRING:"swap"}},14 actor: { wallet_pubkey: {{STRING:"7EcD..."}} },15 constraints: {16 max_spend: [{ mint: SOL_MINT, amount: {{STRING:"1000000000"}} }],17 min_receive: [{ mint: USDC_MINT, amount: {{STRING:"95000000"}} }],18 allowed_programs: [],19 forbidden_accounts: [],20 },21 preconditions: {22 required_accounts: [],23 token_accounts: [],24 blockhash_ttl_seconds: 60,25 },26 metadata: {27 dapp: { name: {{STRING:"My App"}}, url: {{STRING:"https:{{COMMENT://myapp.com"}} },}}28 human_summary: {{STRING:"Swap 1 SOL {{KEYWORD:for}} at least 95 USDC"}},29 },30});3132{{COMMENT:// Sign}}33{{KEYWORD:const}} signed = {{KEYWORD:await}} signIntent(intent, {34 publicKey: wallet.publicKey.toBase58(),35 sign: (msg) => wallet.signMessage(msg),36});3738{{COMMENT:// Verify}}39{{KEYWORD:const}} result = {{KEYWORD:await}} verifyIntent(signed);40console.log(result.ok); {{COMMENT:// true}}4142{{COMMENT:// Summarize {{KEYWORD:for}} wallet display}}43{{KEYWORD:const}} summary = summarizeIntent(signed);44console.log(summary.title); {{COMMENT:// {{STRING:"Swap via My App"}}}}45console.log(summary.bullets); {{COMMENT:// [{{STRING:"Spend up to 1 SOL"}}, ...]}}Key Functions
createIntent(input)Create an unsigned intent manifest with auto-generated ID and timestamp.
signIntent(intent, signer)Sign an intent with a wallet adapter. Returns new intent with signature attached.
verifyIntent(intent, options?)Verify signature, expiration, and optionally check network and required signers.
summarizeIntent(intent)Generate a wallet-friendly summary with title, bullets, and risk flags.
enforceConstraints(intent, observed)Check if observed on-chain state satisfies intent constraints.
fetchIntent(url, options?)Fetch and validate an intent manifest from a URL.
Rust
intentrail
cargo add intentrail1use intentrail::{IntentManifest, verify_intent, VerifyOptions, hash_manifest_hex};23{{COMMENT:// Parse {{KEYWORD:from}} JSON}}4{{KEYWORD:let}} json = r#{{STRING:"{"}}intent_version{{STRING:":"}}1.0{{STRING:",...}"}}#;5{{KEYWORD:let}} manifest: IntentManifest = serde_json::from_str(json)?;67{{COMMENT:// Verify}}8{{KEYWORD:let}} options = VerifyOptions::default();9{{KEYWORD:let}} result = verify_intent(&manifest, &options)?;1011{{KEYWORD:if}} result.ok {12 println!({{STRING:"Intent is valid"}});13} {{KEYWORD:else}} {14 {{KEYWORD:for}} error in result.errors {15 println!({{STRING:"Error: {}"}}, error.message);16 }17}1819{{COMMENT:// Hash}}20{{KEYWORD:let}} hash = hash_manifest_hex(&manifest)?;21println!({{STRING:"Hash: {}"}}, hash);Key Functions
verify_intent(&manifest, &options)Verify an intent manifest including signatures and expiration.
hash_manifest(&manifest)Compute SHA-256 hash of the canonical manifest representation.
canonicalize_manifest(&manifest)Get the canonical JSON string for hashing.
verify_signature(&manifest, signer)Verify a single Ed25519 signature against the manifest.
Python
intentrail
pip install intentrail1{{KEYWORD:from}} intentrail {{KEYWORD:import}} IntentManifest, verify_intent, VerifyOptions2{{KEYWORD:from}} intentrail.hash {{KEYWORD:import}} hash_manifest_hex3{{KEYWORD:import}} json45# Parse {{KEYWORD:from}} JSON6with open({{STRING:"intent.json"}}) as f:7 data = json.load(f)89manifest = IntentManifest(**data)1011# Verify12result = verify_intent(manifest)13{{KEYWORD:if}} result.ok:14 print({{STRING:"Intent is valid"}})15{{KEYWORD:else}}:16 {{KEYWORD:for}} error in result.errors:17 print(f{{STRING:"Error: {error.message}"}})1819# Hash20hash_hex = hash_manifest_hex(manifest)21print(f{{STRING:"Hash: {hash_hex}"}})CLI
The Python package includes a CLI for validation and hashing:
# Validate an intent
intentrail validate intent.json
# Hash an intent
intentrail hash intent.json
# Output canonical form
intentrail canonicalize intent.jsonCross-SDK Compatibility
All SDKs implement identical canonicalization and hashing algorithms. The same intent manifest will produce the same SHA-256 hash in TypeScript, Rust, and Python.
This is verified by shared test fixtures. If you find a discrepancy, please open an issue.