Contracts
Understanding ink! smart contract development in inkathon
Tech Stack
Package | Description | Scope |
---|---|---|
🥟 Bun | Performant workspace & script manager | Contracts |
🚢 Cargo | Rust package manager | Contracts |
🦑 ink! | Rust-based smart contract language for Polkadot | Contracts |
⚙️ TypeScript | Type-safe programming language | Scripts |
🛠️ Biome | Modern Linter & Formatter for TypeScript | Scripts |
⛓️ Papi | Contract Type Generation | Scripts |
💥 Pop CLI | Setup environment and manage smart contracts | Scripts |
📦 cargo contract | Build smart contracts | Scripts |
📦 ink-node | Local ink! node for development | Scripts |
File Structure
Available Commands
Setup Environment
Make sure to follow our contract setup guide first, before running any commands.
Execute from the contracts directory or root with -F contracts
:
# Development
bun run node # Start local ink-node
bun run build # Build all contracts
bun run codegen # Generate TypeScript types
bun run deploy # Deploy contracts
# Code Quality (Scripts)
bun run lint # Run linting checks
bun run lint:fix # Auto-fix issues
bun run typecheck # TypeScript checking
# Maintenance
bun run clean # Remove build artifacts
Build System
The build script (build.sh
) which runs on bun run build
automatically:
- Detects all contracts in
/src
- Builds each with
cargo contract build --release
- Copies artifacts to
/deployments
(under version control) - Organizes by contract name
Output Structure
Type Generation
- Build contracts to generate metadata
- Run
bun run codegen
to create TypeScript descriptors with Papi undercontracts/.papi/
(partially under version control) - Import types in frontend code
import { contracts } from '@polkadot-api/descriptors'
// Create fully-typed contract SDK
const sdk = createReviveSdk(api, contracts.flipper)
const contract = sdk.getContract(flipper.evmAddresses[chain])
Deployment Management
The highly customizable deploy.ts
script handles:
- Account & chain management (defaults to
//Alice
) - Contract instantiation
- Address export to TypeScript files
Environment
Depending on the CHAIN
variable (default: dev
), the script will read secret environment variables (i.e. ACCOUNT_URI
) from the .env.<chain>
file dynamically (e.g. .env.dev
or .env.pop
).
This is useful for deploying to different networks from different accounts.
Deployment Gas Fees
When setting ACCOUNT_URI
to a custom account while using the local development node, make sure
to fund your account first. – The most convenient way to do this is using the Polkadot-JS
UI. Connect it to your local node and send some funds
from Alice
via the Accounts tab.
Output Structure
Deployments create TypeScript files for each chain co-located with the contract metadata:
Exported Addresses
export const evmAddress = '0x...'
export const ss58Address = '5...'
import { evmAddress, ss58Address } from "contracts/deployments/<contract-name>/<chain-name>"
// Create fully-typed contract SDK & instance
const sdk = createReviveSdk(api, contracts.<contract-name>)
const contract = sdk.getContract(evmAddress)