← Back to Resources

Smart Contracts Creation and Management Guide

Overview

Our platform uses a sophisticated modular smart contract architecture built on the SEI Network. This guide covers how to create, manage, and interact with smart contracts for construction project management.

What are Smart Contracts?

Smart contracts are self-executing contracts with terms directly written into code. They automatically execute when predetermined conditions are met, ensuring trustless and transparent operations.

Key Benefits

Our Modular Architecture

Core Modules

Each project deploys multiple interconnected smart contracts:

  1. ProjectCore - Main coordination and access control
  2. PaymentManager - Financial operations and escrow
  3. DocumentManager - Document storage and verification
  4. SecurityManager - Security and fraud detection
  5. ComplianceManager - Regulatory compliance
  6. MilestoneManager - Progress tracking and validation

How Modules Work Together

graph TD
    A[ProjectCore] --> B[PaymentManager]
    A --> C[DocumentManager]
    A --> D[SecurityManager]
    A --> E[ComplianceManager]
    A --> F[MilestoneManager]
    B --> G[Automatic Payments]
    C --> H[Document Verification]
    F --> I[Progress Validation]

Creating Smart Contracts

Using the Contract Factory

The easiest way to create smart contracts is through our Contract Factory:

  1. Access the Factory: Navigate to Contracts → Contract Factory
  2. Fill Project Details: Provide project information
  3. Set Participants: Add all project stakeholders
  4. Configure Payments: Set milestone-based payment schedule
  5. Deploy: Submit transaction to deploy all modules

Manual Creation (Advanced)

For advanced users, contracts can be deployed manually:

// Example: Manual contract deployment
const factory = new ethers.Contract(
    FACTORY_ADDRESS,
    FACTORY_ABI,
    signer
);

const tx = await factory.createProject({
    projectName: "Construction Project",
    totalValue: ethers.parseEther("1000"),
    participants: ["0x...", "0x..."],
    milestones: [25, 25, 25, 25] // Percentage splits
});

const receipt = await tx.wait();
console.log("Project deployed at:", receipt.logs[0].address);

Managing Smart Contracts

Contract Lifecycle

  1. Initialization - Contract deployed with basic parameters
  2. Configuration - Participants added, roles assigned
  3. Active - Project running, milestones being tracked
  4. Completion - Final payments released, contract finalized

Key Management Tasks

Adding Participants

await projectCore.addParticipant(
    participantAddress,
    ethers.id("CONTRACTOR_ROLE")
);

Managing Milestones

// Mark milestone as complete
await milestoneManager.completeMilestone(milestoneId);

// Trigger payment release
await paymentManager.releasePayment(milestoneId);

Document Management

// Upload and sign document
const docHash = await uploadToIPFS(documentFile);
await documentManager.addDocument(
    "Contract Amendment",
    docHash,
    "0x" + keccak256(documentFile)
);

Security Best Practices

Access Control

Transaction Safety

Emergency Procedures

Advanced Features

Upgradeability

Our contracts use OpenZeppelin's UUPS pattern for safe upgrades:

// Upgrade contract implementation
function upgradeTo(address newImplementation) external onlyRole(UPGRADER_ROLE) {
    _authorizeUpgrade(newImplementation);
    _upgradeTo(newImplementation);
}

Event Monitoring

Real-time event tracking for contract activities:

projectCore.on('MilestoneCompleted', (milestoneId, completedBy) => {
    console.log(`Milestone ${milestoneId} completed by ${completedBy}`);
    // Trigger UI updates
});

Integration with Platform

Contracts automatically sync with our platform database:

Troubleshooting

Common Issues

Transaction Failures

Contract Interaction Problems

Getting Help

Best Practices Summary

  1. Always test on testnet first
  2. Use the Contract Factory for standard deployments
  3. Implement proper access controls
  4. Monitor contract events regularly
  5. Keep contract addresses secure
  6. Plan for upgrades and maintenance
  7. Regular security audits
  8. Backup critical contract data

For more detailed information, see our Contract Factory Guide and Security Practices Guide.

← Back to Resources