Skip to content

ogazboiz/ink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ¦€ Ink! Smart Contracts Collection

A comprehensive collection of ink! smart contracts and modern frontend applications built for the Polkadot ecosystem. This repository showcases various contract implementations, from basic token standards to complex governance systems, along with production-ready React frontends for seamless user interaction.

🧭 Quick Navigation

Smart Contracts

Frontend Applications

πŸ“ Project Structure

πŸ“¦ Smart Contracts (Rust + ink! v6)

Contract Description Technology Link
πŸ›οΈ Governance DAO Governance System ink! v6.0.0-alpha.4 πŸ“ governance/
πŸͺ™ PSP22 Boilerplate PSP22 Token Standard ink! v5.1.1 πŸ“ ink-bootcamp-erc20-boilerplate/
🏒 Advanced Token ERC-20 Style Token ink! v5.1.1 πŸ“ Token/
βœ… Simple Todo Vec-based Todo List ink! v5.1.1 πŸ“ todo/
βœ… Todo Map Mapping-based Todo List ink! v5.1.1 πŸ“ todo_map/
πŸͺ™ v6 PSP22 Modern PSP22 Token ink! v6.0.0-alpha.4 πŸ“ v6psp20/
🐷 Piggy Bank Savings Contract ink! v6.0.0-alpha.4 πŸ“ v6psp20piggybank/

🎨 Frontend Applications

Application Description Technology Link
πŸ›οΈ Governance DApp DAO Governance Frontend Next.js 15 + React 19 πŸ“ governance-dapp/
πŸͺ™ ERC20 Frontend Token Interaction UI Next.js 15 + React 19 πŸ“ erc20fe/
πŸ“š Web3Bridge Learning Materials React + Vite πŸ“ web3bridge-curriculum/

πŸ“„ Documentation

Document Description Link
πŸ“– Main README This comprehensive guide πŸ“„ README.md

πŸš€ Quick Start

Prerequisites

Before you begin, ensure you have the following installed:

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Add WebAssembly target
rustup target add wasm32-unknown-unknown

# Install cargo-contract
cargo install cargo-contract --force

# Install substrate-contracts-node (for local testing)
cargo install contracts-node --git https://github.com/paritytech/substrate-contracts-node.git

# Install Node.js (for frontend development)
# Visit: https://nodejs.org/

Local Development Setup

  1. Start Local Node
# In a separate terminal
substrate-contracts-node --dev
  1. Build Any Contract
cd <contract-directory>
cargo contract build --release
  1. Deploy Contract
cargo contract instantiate --constructor new --suri //Alice --skip-confirm
  1. Run Frontend
cd frontend/governance-dapp
npm install
npm run dev

πŸ“¦ Smart Contracts

πŸ›οΈ Governance Contract

Location: governance/ Technology: ink! v6.0.0-alpha.4

A comprehensive DAO governance system implementing decentralized decision-making:

Core Features

  • Proposal Management: Create, vote on, and execute proposals
  • Voting System: Multi-option voting with customizable parameters
  • Quorum Requirements: Configurable participation thresholds
  • Execution Delays: Time-locked execution for security
  • Voter Registration: Permission-based voting participation
  • Treasury Management: Fund allocation and spending controls

Key Functions

// Proposal Management
create_proposal(title, description, proposal_type, governance_params, voting_options) -> u32
get_proposal(proposal_id) -> Option<Proposal>
get_all_proposal_ids() -> Vec<u32>

// Voting System
vote(proposal_id, option_index) -> Result<()>
get_user_vote(proposal_id, user) -> Option<Vote>
has_reached_quorum(proposal_id) -> Option<bool>
get_detailed_results(proposal_id) -> Option<Vec<(String, u128)>>

// Voter Management
register_voter() -> Result<()>
is_voter(account) -> bool
get_total_voters() -> u32

// Status Management
update_proposal_status(proposal_id) -> Result<()>
execute_proposal(proposal_id) -> Result<()>

Data Structures

pub struct Proposal {
    pub id: u32,
    pub title: String,
    pub description: String,
    pub proposal_type: ProposalType,        // Treasury, Governance, Technical, Other
    pub governance_params: GovernanceParameters,
    pub voting_options: VotingOptions,      // Custom voting choices
    pub proposer: H160,
    pub created_at: u32,                    // Block number
    pub voting_end: u32,                    // Block number
    pub execution_time: u32,                // Block number
    pub status: ProposalStatus,             // Active, Passed, Rejected, Executed, Expired
    pub vote_counts: Vec<u128>,             // Votes per option
    pub total_voters: u32,
}

pub struct Vote {
    pub voter: H160,
    pub choice: VoteChoice,
    pub timestamp: u32,
    pub weight: u128,
}

πŸͺ™ PSP22 Token Contracts

ink-bootcamp-erc20-boilerplate

Location: ink-bootcamp-erc20-boilerplate/ Technology: ink! v5.1.1

A complete PSP22 token implementation with all standard features:

  • βœ… PSP22 Core - Transfer, approve, and allowance functionality
  • βœ… PSP22 Metadata - Token name, symbol, and decimals
  • βœ… PSP22 Mintable - Mint new tokens
  • βœ… PSP22 Burnable - Burn existing tokens
  • βœ… Safe Arithmetic - Overflow protection
  • βœ… Comprehensive Error Handling

Token Contract

Location: Token/ Technology: ink! v5.1.1

Advanced ERC-20 style token with enterprise features:

  • Core Functionality: Transfer, approve, allowance
  • Burn Mechanism: Users can burn their tokens
  • Pausable: Emergency pause functionality
  • Blacklist: Address blacklisting capability
  • Batch Operations: Multi-recipient transfers
  • Owner Controls: Administrative functions

v6psp20

Location: v6psp20/ Technology: ink! v6.0.0-alpha.4

Modern PSP22 token implementation using ink! v6 with:

  • Latest ink! v6 features and optimizations
  • Enhanced storage patterns
  • Improved error handling
  • Polkadot VM compatibility

🐷 Piggy Bank Contract

Location: v6psp20piggybank/ Technology: ink! v6.0.0-alpha.4

A savings contract that allows users to:

  • Deposit Tokens: Save PSP22 tokens
  • Set Goals: Define savings targets
  • Withdraw: Retrieve funds (with restrictions)
  • Break Piggy Bank: Emergency withdrawal
  • Goal Tracking: Monitor progress

βœ… Todo List Contracts

Simple Todo

Location: todo/ Technology: ink! v5.1.1

Basic todo list implementation using Vec storage:

  • Add tasks
  • Mark tasks as complete
  • Get all tasks
  • Delete tasks
  • Simple storage pattern

Todo with Mapping

Location: todo_map/ Technology: ink! v5.1.1

Optimized todo list using Mapping storage:

  • More efficient storage
  • Individual task access
  • Better gas optimization
  • Scalable design

🎨 Frontend Applications

πŸ›οΈ DAO Governance DApp

Location: frontend/governance-dapp/ Technology: Next.js 15.5.3 + React 19 + TypeScript

A production-ready governance frontend with real contract integration:

Features

  • Real Contract Integration: Direct interaction with deployed governance contract
  • Wallet Connection: Support for multiple Polkadot wallets
  • Proposal Management: Create, view, and vote on proposals
  • Voter Registration: Join governance participation
  • Real-time Updates: Live data from blockchain
  • Responsive Design: Mobile-first UI with Tailwind CSS
  • Type Safety: Full TypeScript integration

Key Components

src/
β”œβ”€β”€ app/                    # Next.js App Router pages
β”‚   β”œβ”€β”€ page.tsx           # Home page with stats
β”‚   β”œβ”€β”€ proposals/         # Proposal listing and voting
β”‚   β”œβ”€β”€ create/            # Create new proposals
β”‚   β”œβ”€β”€ dashboard/         # User dashboard
β”‚   └── voters/            # Voter statistics
β”œβ”€β”€ components/            # Reusable UI components
β”‚   β”œβ”€β”€ create-proposal.tsx
β”‚   β”œβ”€β”€ governance-dashboard.tsx
β”‚   └── shared/            # Shared components
β”œβ”€β”€ contexts/              # React Context providers
β”‚   β”œβ”€β”€ governance-client.tsx  # Contract interaction
β”‚   └── types.ts           # TypeScript definitions
└── lib/                   # Utilities and types
    └── governance-types.ts

Technology Stack

  • Framework: Next.js 15.5.3 with App Router
  • UI Library: Radix UI + Tailwind CSS
  • Web3 Integration: Polkadot API + Typink
  • State Management: React Context API
  • Type Safety: TypeScript 5.9.2
  • Wallet Integration: Talisman Connect

ERC20 Frontend

Location: frontend/erc20fe/ Technology: Next.js 15.5.4 + React 19

Modern Next.js application for token interaction:

  • Framework: Next.js 15.5.4 with TypeScript
  • Styling: Tailwind CSS
  • Web3 Integration: Polkadot.js API
  • Features:
    • Wallet connection
    • Token balance display
    • Transfer functionality
    • Transaction history
    • Real-time updates

Web3Bridge Curriculum

Location: frontend/web3bridge-curriculum/ Technology: React + Vite

Educational materials and demos:

  • ink-papi-demo: React + Vite demo application
  • Learning Resources: Comprehensive tutorials
  • Contract Examples: Step-by-step implementations
  • Best Practices: Development guidelines

πŸ› οΈ Development Workflow

Building Contracts

# Development build (faster, with debug info)
cargo contract build

# Production build (optimized, smaller size)
cargo contract build --release

Testing

# Run unit tests
cargo test

# Run integration tests
cargo test --features e2e-tests

Frontend Development

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Start production server
npm start

Deployment Options

1. Local Development

substrate-contracts-node --dev
cargo contract instantiate --constructor new --suri //Alice

2. Contracts UI

Visit: https://contracts-ui.substrate.io/

3. Polkadot.js Apps

Visit: https://polkadot.js.org/apps/

4. Test Networks

  • Rococo Contracts: wss://rococo-contracts-rpc.polkadot.io
  • Aleph Zero Testnet: wss://ws.test.azero.dev

πŸ“š Contract APIs

Common Functions

Most contracts implement these standard functions:

// Token contracts
total_supply() -> Balance
balance_of(owner: AccountId) -> Balance
transfer(to: AccountId, value: Balance) -> Result<(), Error>
approve(spender: AccountId, value: Balance) -> Result<(), Error>

// Todo contracts
add_task(description: String) -> u32
complete_task(id: u32) -> bool
get_task(id: u32) -> Option<Task>
get_all_tasks() -> Vec<Task>

// Governance contracts
create_proposal(title: String, description: String, ...) -> u32
vote(proposal_id: u32, option_index: u32) -> Result<(), Error>
execute_proposal(proposal_id: u32) -> Result<(), Error>
register_voter() -> Result<(), Error>

πŸ”§ Configuration

Cargo.toml Dependencies

All contracts use these core dependencies:

ink! v5 Contracts:

[dependencies]
ink = { version = "5.1.1", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.11", default-features = false, features = ["derive"] }

ink! v6 Contracts:

[dependencies]
ink = { git = "https://github.com/use-ink/ink", tag = "v6.0.0-alpha.4", version = "6.0.0-alpha.4", default-features = false, features = ["unstable-hostfn"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }

Frontend Dependencies

Governance DApp:

{
  "dependencies": {
    "next": "^15.5.3",
    "react": "^19.1.1",
    "polkadot-api": "^1.20.0",
    "@talismn/connect-wallets": "^1.2.8",
    "typink": "^0.5.0",
    "tailwindcss": "^4.1.13"
  }
}

πŸ§ͺ Testing

Unit Tests

cargo test

Integration Tests

cargo test --features e2e-tests

Frontend Tests

cd frontend/governance-dapp
npm test

🚨 Troubleshooting

Common Issues

"CodeRejected" Error

# Install compatible node version
cargo install contracts-node --git https://github.com/paritytech/substrate-contracts-node.git --tag v0.47.0 --locked --force

"Cannot connect to node"

# Check if node is running
substrate-contracts-node --dev

# Verify node health
curl -H "Content-Type: application/json" \
  -d '{"id":1, "jsonrpc":"2.0", "method": "system_health"}' \
  http://localhost:9944

"Insufficient funds"

  • Use pre-funded test accounts: //Alice, //Bob, //Charlie
  • Request funds from testnet faucet

Frontend Build Issues

# Clear Next.js cache
rm -rf .next

# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install

# Rebuild
npm run build

πŸ“– Learning Resources

Documentation

Tools

Community

πŸ—οΈ Architecture Overview

Smart Contract Stack

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Frontend Apps             β”‚
β”‚    (Next.js, React, TypeScript)    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Polkadot API               β”‚
β”‚      (Web3 Integration Layer)      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚        Substrate Runtime           β”‚
β”‚      (Blockchain Infrastructure)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         ink! Contracts             β”‚
β”‚    (Smart Contract Layer)          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Contract Interaction Flow

User β†’ Frontend β†’ Polkadot API β†’ Substrate Node β†’ ink! Contract

Governance DApp Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         User Interface              β”‚
β”‚    (React Components + Tailwind)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Context Providers           β”‚
β”‚    (Wallet + Governance Context)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Contract Client             β”‚
β”‚    (Polkadot API + Typink)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Smart Contract              β”‚
β”‚    (ink! Governance Contract)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎯 Use Cases

Token Contracts

  • DeFi Applications: Lending, borrowing, staking
  • NFT Marketplaces: Payment tokens
  • DAO Governance: Voting tokens
  • Cross-chain Bridges: Bridge tokens

Governance Contracts

  • DAO Management: Decentralized decision making
  • Treasury Management: Fund allocation
  • Protocol Upgrades: Governance-controlled changes
  • Community Voting: Proposal and voting systems

Utility Contracts

  • Todo Lists: Task management dApps
  • Piggy Banks: Savings and goal tracking
  • Escrow Services: Secure fund holding
  • Multi-signature Wallets: Shared control

πŸ”’ Security Considerations

Best Practices Implemented

  • Safe Arithmetic: Overflow/underflow protection
  • Access Control: Owner-only functions
  • Input Validation: Parameter checking
  • Event Logging: Comprehensive event emission
  • Error Handling: Detailed error messages
  • Testing: Unit and integration tests

Security Features

  • Pausable contracts for emergency stops
  • Blacklist functionality for malicious addresses
  • Time-locked operations for critical functions
  • Multi-signature requirements for sensitive operations
  • Quorum requirements for governance decisions

πŸ“ˆ Performance Optimizations

Storage Patterns

  • Mapping vs Vec: Efficient storage selection
  • Packed Structs: Optimized data layout
  • Lazy Loading: On-demand data access
  • Batch Operations: Reduced transaction costs

Gas Optimization

  • Minimal Storage: Only store necessary data
  • Efficient Algorithms: Optimized computation
  • Event Optimization: Selective event emission
  • Contract Size: Minimized WASM size

Frontend Optimizations

  • Code Splitting: Lazy loading of components
  • Image Optimization: Next.js image optimization
  • Bundle Analysis: Webpack bundle analyzer
  • Caching: Strategic caching strategies

🀝 Contributing

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

Code Standards

  • Follow Rust conventions
  • Add comprehensive tests
  • Document public functions
  • Use meaningful variable names
  • Implement proper error handling
  • Follow TypeScript best practices
  • Use consistent formatting

Pull Request Process

  1. Ensure all tests pass
  2. Update documentation
  3. Add changelog entries
  4. Request code review
  5. Address feedback
  6. Merge after approval

πŸ“„ License

This project is provided as-is for educational purposes. Individual contracts may have different licenses - check each contract's directory for specific licensing information.

πŸ†˜ Support

For issues and questions:

  • Create an issue in the repository
  • Join the ink! Discord community
  • Check the troubleshooting section above
  • Review the documentation links

πŸŽ‰ Recent Updates

Governance DApp v1.0.0

  • βœ… Real contract integration with Polkadot API
  • βœ… Production-ready build system
  • βœ… Comprehensive error handling
  • βœ… Mobile-responsive design
  • βœ… Type-safe contract interactions
  • βœ… Wallet connection support
  • βœ… Real-time blockchain data

Smart Contracts v6.0.0

  • βœ… ink! v6.0.0-alpha.4 support
  • βœ… Enhanced governance features
  • βœ… Improved error handling
  • βœ… Optimized storage patterns
  • βœ… Comprehensive test coverage

πŸ¦€ Built with Rust + ink! v6.0.0-alpha.4

This collection demonstrates the power and flexibility of ink! smart contracts in the Polkadot ecosystem, from simple utility contracts to complex governance systems with production-ready frontends.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published