Prerequisites
Before deploying contracts, ensure you have:Compilation Process
Contracts are written in assembly and compiled to bytecode:Writing Assembly
Create a contract file (e.g.,counter.asm):
counter.asm
Compiling to Bytecode
The assembler compiles assembly to bytecode:- Lexical analysis - Tokenizes the source
- Parsing - Builds an AST
- Two-pass compilation:
- Pass 1: Collect label addresses
- Pass 2: Emit bytecode with resolved references
The
minichain deploy command handles compilation automatically - you just provide the .asm source file.Deployment Transaction
Using the CLI
Deploy a contract using the CLI:Account name (keypair file without
.json extension)Path to assembly source file (
.asm)Maximum gas to spend on deployment
Price per unit of gas
Blockchain data directory
Deployment Output
Successful deployment shows:The contract address is deterministically derived from the deployer’s address and nonce.
Understanding Deployment
Contract Address Calculation
Contract addresses are deterministic:- Predictability - You know the address before deployment
- No collisions - Each deployment creates a unique address
- Reproducibility - Same deployer + nonce = same address
Gas Estimation
Deployment gas cost formula:- 21,000 - Base transaction cost
- 200 per byte - Bytecode storage cost
Transaction Lifecycle
Submit transaction
The
minichain deploy command creates and signs a deployment transaction, then submits it to the mempool.Execute deployment
When the block is produced, the deployment transaction executes:
- Bytecode is stored at the contract address
- Account balance is created
- Gas is consumed
Producing a Block
After deployment, produce a block to include the transaction:- Gathers transactions from the mempool
- Executes each transaction
- Creates a new block
- Updates the blockchain state
After block production, your contract is live and callable!
Advanced Deployment
Programmatic Deployment
Deploy contracts programmatically:Deployment with Constructor
While Minichain doesn’t have separate constructors, you can implement initialization logic:Deployment Verification
Verify deployment succeeded:Troubleshooting
Compilation Errors
Compilation Errors
Undefined label:Ensure all labels used in Use registers R0-R15 only.
LOADI or JUMP instructions are defined.Invalid register:Insufficient Balance
Insufficient Balance
Gas Limit Too Low
Gas Limit Too Low
Contract Already Exists
Contract Already Exists
Contract addresses are deterministic. If you see “contract already exists”, either:
- You already deployed from this account at this nonce
- Deploy from a different account
- Execute a transaction to increment your nonce
Next Steps
Call Contracts
Learn how to interact with deployed contracts
Examples
See complete deployment examples
Gas & Fees
Understand gas costs and optimization