Alkanes Contracts
Alkanes contracts are smart contracts that run on Bitcoin, enabling programmable functionality similar to what Ethereum smart contracts provide. They allow developers to create decentralized applications (dApps) directly on Bitcoin's L1 blockchain, without requiring additional layers or sidechains.
Key Features
Native Bitcoin Integration
Contracts interact directly with Bitcoin transactions and UTXOs
State Management
Maintain contract state between interactions
Composability
Contracts can interact with each other
WASM Runtime
Written in Rust, compiled to WebAssembly
Contract Structure
An Alkanes contract typically consists of:
- State Storage – Key-value storage for maintaining contract data
- Opcodes – Numbered functions that define contract actions
- Response Handling – Logic for returning data and managing assets
- Asset Management – Capabilities for handling Bitcoin and Alkanes tokens
Alkanes Tokens
Alkanes token contracts are a standardized implementation pattern that represent fungible tokens - digital assets where each unit is identical and interchangeable.
At their core, Alkanes token contracts maintain a mapping of addresses to a balance sheet, tracking token ownership through key-value state storage. The critical operations are transfers (moving tokens between addresses) and approvals (allowing another address to transfer tokens on your behalf).
Token Features
- Minting and burning capabilities (often with access controls)
- Token metadata (name, symbol, decimals)
- Transfer hooks for additional logic
- Supply caps or other monetary policy
- Snapshot functionality for governance
Factory Contracts
Alkanes factory contracts are a design pattern that enables programmatic cloning of a base contract. For example, you may want to deploy a single factory contract that defines the logic for token minting and distribution and then use clones of that contract to create individual tokens that inherit that logic.
A factory contract uses Alkanes's FACTORYRESERVED opcode to deploy new contract instances, typically taking parameters like token name, symbol, total supply, and mint parameters.
Factory Use Cases
- Deploy pairs of tokens for AMMs
- Create wrapped asset tokens
- Mint governance tokens for new projects
- Standardized, gas-efficient token deployment
Example Contract
use alkanes_std::prelude::*;
use alkanes_support::context::Context;
#[derive(Default)]
pub struct MyAlkane {
counter: u64,
}
impl MyAlkane {
pub fn new() -> Self {
Self { counter: 0 }
}
pub fn increment(&mut self) {
self.counter += 1;
}
pub fn get_count(&self) -> u64 {
self.counter
}
}
// Export the contract
alkane!(MyAlkane);Next Steps
- Quick Start guide - Deploy your first contract
- CLI commands - Deployment and interaction
- API - Programmatic access