Skip to content

Templates

Brandon Brooks edited this page Jan 22, 2026 · 1 revision

Templates

ContractKit includes four production-ready templates, each with OpenZeppelin-based implementations.

ERC20 Token

A fungible token with role-based access control for minting.

/contractkit:new erc20 MyToken MTK

Features:

  • ERC20 standard implementation
  • AccessControl for role management
  • MINTER_ROLE for controlled minting
  • Admin can grant/revoke minting rights

Contract: Token.sol

contract Token is ERC20, AccessControl {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

    function mint(address to, uint256 amount) external onlyRole(MINTER_ROLE);
}

ERC721 NFT

An NFT collection with role-based minting and metadata support.

/contractkit:new erc721 MyNFT MNFT

Features:

  • ERC721 standard implementation
  • AccessControl for role management
  • Auto-incrementing token IDs
  • Configurable base URI for metadata
  • totalSupply tracking

Contract: NFT.sol

contract NFT is ERC721, AccessControl {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

    function mint(address to) external onlyRole(MINTER_ROLE) returns (uint256);
    function setBaseURI(string memory baseURI_) external onlyRole(DEFAULT_ADMIN_ROLE);
}

Escrow

A three-party escrow contract for secure payments.

/contractkit:new escrow MyEscrow

Features:

  • Three parties: payer, payee, arbiter
  • State machine: Created → Funded → Released/Refunded/Disputed
  • ReentrancyGuard protection
  • Dispute resolution by arbiter

Contract: Escrow.sol

contract Escrow is ReentrancyGuard {
    function fund() external payable onlyPayer;
    function release() external onlyPayer;
    function refund() external onlyPayee;
    function dispute() external onlyParty;
    function resolve(address winner) external onlyArbiter;
}

Flow:

  1. Payer creates escrow with payee, arbiter, and amount
  2. Payer funds the escrow
  3. On completion: payer releases funds to payee
  4. On cancellation: payee refunds to payer
  5. On dispute: arbiter resolves to either party

Vault

A simple ETH vault with deposit/withdraw and pause functionality.

/contractkit:new vault MyVault

Features:

  • Deposit and withdraw ETH
  • Balance tracking per user
  • Pausable by PAUSER_ROLE
  • ReentrancyGuard protection
  • AccessControl for admin operations

Contract: Vault.sol

contract Vault is ReentrancyGuard, AccessControl {
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

    function deposit() external payable whenNotPaused;
    function withdraw(uint256 amount) external nonReentrant whenNotPaused;
    function withdrawAll() external nonReentrant whenNotPaused;
    function pause() external onlyRole(PAUSER_ROLE);
    function unpause() external onlyRole(PAUSER_ROLE);
}

Template Structure

Each template includes:

myproject/
├── src/
│   └── Contract.sol      # Main contract
├── test/
│   └── Contract.t.sol    # Foundry tests
├── script/
│   ├── Deploy.s.sol      # Deployment script
│   └── Interact.s.sol    # Interaction script
├── foundry.toml          # Foundry config
├── README.md             # Project readme
├── SECURITY.md           # Security considerations
└── THREAT_MODEL.md       # Threat analysis

Security Notice

All templates are starting points, not audited production code. Before mainnet deployment:

  1. Get an independent security audit
  2. Review and customize for your needs
  3. Test thoroughly on testnet
  4. Consider bug bounty programs

Clone this wiki locally