Reference smart contract implementations for the GLIN AI-powered dApp platform. These contracts enable developers to build decentralized applications across legal, healthcare, real estate, and other industries.
Purpose: Milestone-based payment escrow with AI oracle integration
Features:
- β Multi-party agreements (client & provider)
- β Milestone-based payment releases
- β Dispute resolution mechanism
- β AI oracle verification support
- β Platform fee collection (configurable)
- β Deadline tracking per milestone
Use Cases:
- Freelance contracts
- Service agreements
- Real estate transactions
- Legal retainers
- Construction projects
Key Functions:
create_agreement() // Create escrow with milestones
complete_milestone() // Provider marks work done
approve_and_release() // Client/oracle approves payment
raise_dispute() // Either party disputes milestone
resolve_dispute() // Oracle resolves disputePurpose: Staking-based professional registry with reputation system
Features:
- β Role-based registration (Lawyer, Doctor, Arbitrator, etc.)
- β Stake requirements per role
- β Reputation scoring (0-100+)
- β Review/rating system
- β Slashing for misbehavior
- β Profile metadata (IPFS URI)
Use Cases:
- Professional verification
- Service provider discovery
- Reputation-based matching
- Quality assurance
- Credential validation
Key Functions:
register() // Register as professional with stake
increase_stake() // Add more stake to profile
submit_review() // Rate a professional (1-5 stars)
slash() // Penalize misbehavior (owner only)
withdraw_stake() // Exit registryPurpose: Decentralized arbitration with weighted voting
Features:
- β Stake-weighted voting
- β Configurable voting periods
- β Quorum requirements
- β Appeal mechanism (one appeal per dispute)
- β Evidence submission (IPFS)
- β Arbitrator reputation tracking
Use Cases:
- Contract dispute resolution
- Community governance
- Decentralized justice
- Peer-to-peer conflict resolution
- DAO decision making
Key Functions:
register_arbitrator() // Stake to become arbitrator
create_dispute() // Open new dispute
start_voting() // Begin arbitration process
vote() // Cast weighted vote
finalize_dispute() // Execute final decision
appeal_dispute() // Request re-vote (one-time)- Install Rust & Cargo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh- Install cargo-contract
cargo install cargo-contract --force- Add wasm32 target
rustup target add wasm32-unknown-unknowncd glin-contracts/scripts
./build-all.shThis will:
- Build all 3 contracts in release mode
- Generate
.contractand.wasmfiles - Copy artifacts to
target/ink/
cd glin-contracts/escrow
cargo contract build --release# Test all contracts
cargo test --workspace
# Test specific contract
cd escrow && cargo test- Start GLIN node
cd ../glin-chain
./target/release/glin-node --dev- Deploy contracts
cd ../glin-contracts/scripts
./deploy-testnet.shexport TESTNET_URL="wss://testnet.glin.network"
export SURI="//YourSeedPhrase" # NEVER commit this!
./deploy-testnet.sh// Client creates escrow for 2 milestones
escrow.create_agreement(
provider_address,
vec!["Design mockups", "Final implementation"],
vec![500 * GLIN, 1500 * GLIN],
vec![timestamp_week_1, timestamp_week_4],
dispute_timeout,
Some(oracle_address)
)// Lawyer registers with 100 GLIN stake
registry.register(
ProfessionalRole::Lawyer,
"ipfs://QmYourMetadata" // JSON with credentials
)// Claimant creates dispute
arbitration.create_dispute(
defendant_address,
"Contract breach - undelivered services",
"ipfs://QmEvidenceBundle"
)βββββββββββββββββββ
β GenericEscrow β
ββββββββββ¬βββββββββ
β calls
βΌ
βββββββββββββββββββ ββββββββββββββββββββ
β ArbitrationDAO βββββββΊβ ProfessionalReg β
βββββββββββββββββββ ββββββββββββββββββββ
β² β²
β β
ββββββββββββββββββββββββββ
Check arbitrator status
AI Backend (Rust/Axum)
β
βββΊ Listens to contract events
βββΊ Submits AI analysis as oracle
βββΊ Caches data for fast queries
βββΊ Provides REST API for dApps
- Create directory
mkdir glin-contracts/my_contract- Add to workspace (
Cargo.toml)
members = [
"escrow",
"registry",
"arbitration",
"my_contract", # Add here
]- Create contract (
my_contract/lib.rs)
#![cfg_attr(not(feature = "std"), no_std, no_main)]
#[ink::contract]
mod my_contract {
#[ink(storage)]
pub struct MyContract {
// Your storage
}
impl MyContract {
#[ink(constructor)]
pub fn new() -> Self {
Self {}
}
#[ink(message)]
pub fn my_function(&self) {}
}
}- Update build script
Add contract to
scripts/build-all.sh
Each contract includes built-in tests:
cd escrow
cargo test
# With verbose output
cargo test -- --nocapture# Start local node
./glin-chain/target/release/glin-node --dev
# Run integration tests (coming soon)
cd glin-contracts/integration-tests
cargo testAll contracts require deposits for storage:
- Per item: 1 GLIN
- Per byte: 0.001 GLIN
- Max code size: 256 KB
- Max storage key: 128 bytes
- Transient storage: 1 MB
- β Always validate inputs
- β Use Checks-Effects-Interactions pattern
- β Emit events for important state changes
- β Implement access control for sensitive functions
- β Handle overflows/underflows
- β Test edge cases thoroughly
| Operation | Estimated Cost (GLIN) |
|---|---|
| Deploy Escrow | ~0.5 |
| Create Agreement | ~0.1 |
| Complete Milestone | ~0.05 |
| Register Professional | ~0.2 |
| Submit Review | ~0.05 |
| Create Dispute | ~0.1 |
| Cast Vote | ~0.05 |
Actual costs may vary based on network congestion
import { ContractPromise } from '@polkadot/api-contract';
// Connect to contract
const contract = new ContractPromise(
api,
escrowMetadata,
'CONTRACT_ADDRESS'
);
// Call contract method
await contract.tx
.completeM ilestone({ value: 0, gasLimit: -1 }, agreementId, 0)
.signAndSend(account);
// Query contract state
const { output } = await contract.query
.getAgreement(account.address, { gasLimit: -1 }, agreementId);import { GlinContracts } from '@glin/sdk';
const contracts = new GlinContracts(api);
await contracts.escrow.createAgreement(...);- ink! Documentation: https://use.ink
- Substrate Docs: https://docs.substrate.io
- GLIN Blockchain: ../glin-chain
- GLIN Backend: ../glin-backend
- Example dApps: ../examples
Apache 2.0 - see LICENSE file
- Fork the repository
- Create feature branch (
git checkout -b feature/my-contract) - Write tests
- Ensure
cargo testpasses - Submit pull request
- GitHub Issues: https://github.com/glin/glin-chain/issues
- Discord: [Coming Soon]
- Email: dev@glin.network
Phase 1 (Current): β Core contracts
- GenericEscrow
- ProfessionalRegistry
- ArbitrationDAO
Phase 2 (Q2 2025): DeFi & NFT Contracts
- Lending pools
- NFT marketplace
- Staking derivatives
Phase 3 (Q3 2025): Cross-Chain
- XCM integration
- Bridge contracts
- Multi-chain deployment
Phase 4 (Q4 2025): Advanced Features
- Privacy contracts (zk-SNARKs)
- Automated market makers
- Prediction markets
Built with β€οΈ by the GLIN Team