inkathoninkathon

Contracts

Understanding ink! smart contract development in inkathon

Tech Stack

PackageDescriptionScope
🥟 BunPerformant workspace & script managerContracts
🚢 CargoRust package managerContracts
🦑 ink!Rust-based smart contract language for PolkadotContracts
⚙️ TypeScriptType-safe programming languageScripts
🛠️ BiomeModern Linter & Formatter for TypeScriptScripts
⛓️ PapiContract Type GenerationScripts
💥 Pop CLISetup environment and manage smart contractsScripts
📦 cargo contractBuild smart contractsScripts
📦 ink-nodeLocal ink! node for developmentScripts

File Structure

package.json
build.sh
codegen.sh
deploy.sh
Cargo.toml

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:

  1. Detects all contracts in /src
  2. Builds each with cargo contract build --release
  3. Copies artifacts to /deployments (under version control)
  4. Organizes by contract name

Output Structure

<contract-name>.contract
<contract-name>.json
<contract-name>.polkavm

Type Generation

  1. Build contracts to generate metadata
  2. Run bun run codegen to create TypeScript descriptors with Papi under contracts/.papi/ (partially under version control)
  3. Import types in frontend code
Frontend
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:

<chain-name>.ts

Exported Addresses

deployments/<contract-name>/<chain-name>.ts
export const evmAddress = '0x...'
export const ss58Address = '5...'
Frontend
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)

Learn More