Kraflab is a modular and extensible smart contract suite that facilitates:
- Role-based access control for organizations and communities
- Soulbound NFTs for identity tagging and licensing
- Secure, deterministic contract deployment using CREATE2
- Off-chain verified actions (e.g., payment, license ownership)
kraflab-smart-contracts/
├── contracts/
│ ├── base/
│ │ └── KraflabTag.sol
│ ├── entity/
│ │ ├── Government.sol
│ │ ├── Community.sol
│ │ └── Creator.sol
│ ├── interface/
│ │ ├── IKraflab.sol
│ │ ├── IKraflabLicense.sol
│ │ └── IKraflabTag.sol
│ ├── registry/
│ │ └── ContractRegistry.sol
│ ├── Kraflab.sol
│ ├── KraflabFactory.sol
│ └── KraflabLicense.sol
├── scripts/
│ └── 1_deploy_kraflab.ts
| └── 2_deploy_license.ts
| └── 3_deploy_factory.ts
| └── 4_deploy_tag.ts
├── test/
│ └── index.ts
├── config/
│ ├── ContractArguments.ts
│ └── CollectionConfig.ts
├── package.json
└── hardhat.config.ts
For immediate local development setup:
# Clone and setup
yarn install
yarn compile
# Start local blockchain
npx hardhat node &
# Deploy and configure everything in one command
npx hardhat run scripts/setup_local_all.ts --network localhostFor immediate debugging with enhanced logging:
# Clone and setup
yarn install
yarn compile
# Start debug node with monitor (recommended for development)
./start_debug_node.sh --debug --monitor
# In another terminal, test the setup
yarn test-debugyarn installyarn compileyarn test
# With gas reporting:
yarn test-gasThe easiest way to set up a complete local environment:
# Start local blockchain
npx hardhat node &
# Deploy and configure everything
npx hardhat run scripts/setup_local_all.ts --network localhostThis script will:
- ✅ Deploy Kraflab and KraflabLicense contracts (if not already deployed)
- ✅ Set up root permissions for the deployer
- ✅ Configure minter permissions for license creation
- ✅ Verify the complete setup
This README explains how to deploy all smart contracts locally (on localhost) using the deploy.sh script.
- install dependencies
yarn install
- compile contract first
yarn compile
- give executable access for the script file
chmod +x ./deploy.sh
- run script for localhost
./deploy.sh
- you can stop or restart the script using
control + c - you can see the log in
node.logfile
For enhanced debugging during development:
# Start with debug logging and monitoring
./start_debug_node.sh --debug --monitor
# Test the debug setup
yarn test-debug
# Deploy and configure everything with one script
npx hardhat run scripts/setup_local_all.ts --network localhostThe project includes enhanced debug logging capabilities for local development:
# Start node with normal debug logging
yarn local-node
# Start node with detailed debug logging
yarn local-node:debug
# Start node with full debug logging (very verbose)
yarn local-node:full
# Monitor blockchain activity (run in separate terminal)
yarn monitor-nodeUse the convenient shell script for advanced debugging:
# Basic usage
./start_debug_node.sh
# With detailed debug logging
./start_debug_node.sh --debug
# With full debug logging (very verbose)
./start_debug_node.sh --full-debug
# Start with transaction monitor
./start_debug_node.sh --monitor
# Combine options and save logs to file
./start_debug_node.sh --debug --monitor --log-file- Verbose Hardhat Logging: See internal hardhat operations
- Transaction Monitoring: Real-time transaction details and gas usage
- Block Monitoring: New block notifications with transaction counts
- Contract Interaction Logs: Detailed contract deployment and call information
- Event Logging: Automatic event decoding and display
- Account Monitoring: Balance tracking for test accounts
- Transaction hashes, gas usage, and status
- Contract deployment addresses
- Event emissions and log data
- Block information and timestamps
- Account balances and interactions
- Error details and stack traces
Use these tools to debug contract interactions, monitor gas usage, and trace transaction flows during development.
- Start Debug Node:
./start_debug_node.sh --debug --monitor - Test Setup:
yarn test-debug - Deploy Contracts:
yarn deploy-kraflab,yarn deploy-license, etc. - Monitor Activity: Real-time logs show all transactions and contract interactions
- Debug Issues: Verbose logs help identify gas problems, failed transactions, and contract events
Manages access control via modular inheritance:
- Government for managing organizations
- Community for managing groups and members
- Creator for creator identity
- Uses AccessControl from OpenZeppelin
Key Roles:
- DEFAULT_ADMIN_ROLE: Root admin
- OrgAdmin: Admin per organization
- GroupAdmin: Admin per community
Soulbound ERC721 token representing a verified tag.
- Non-transferable, non-burnable (SoulboundToken error)
- Only mintable by authorized OrgAdmins
- Requires off-chain payment verification
Main Functions:
verifyPayment(address): Marks payment as verifiedmintTag(address): Mints tag if valid, paid, and uniqueverifyTagOwnership(address): Verifies user owns a tagsetUriTag(string): Updates metadata URIpause(), unpause(): Contract pausing mechanism
A deterministic factory for deploying tagged contracts using CREATE2
- Relies on license gating (KraflabLicense)
- Uses ContractRegistry for versioning
Main Functions:
addImplementation(...): Register new implementationdeployTag(...): Deploy a new tag contractpredictedAddress(...): Predict deterministic addresssetActiveLicense(bool): Toggle license enforcement
ERC721 soulbound license token for granting access
- Owned by root admin
- Purchasable by government organization admins
Main Functions:
create(...): Mint new license tokenbuy(uint256, bytes32): Transfer to admin (if valid)checkOwnerShip(...): Validate token ownershipsetUriTag(...): Update metadata URI
| Ensure local node is already running.
For local development, use the unified setup script:
npx hardhat run scripts/setup_local_all.ts --network localhostScripts are located in scripts/:
- 1_deploy_kraflab.ts
- 2_deploy_license.ts
- 3_deploy_factory.ts
- 4_deploy_tag.ts
- setup_local_all.ts (unified local setup)
Run any script using:
yarn hardhat run scripts/1_deploy_kraflab.tsCustom tasks (as defined in package.json):
yarn accounts
yarn test
yarn test-gas
yarn compile- All smart contract roles must be verified before executing restricted functions
- Tags are soulbound; once minted, users cannot transfer, burn, or approve them
- You must call
verifyPayment(account)beforemintTag(account) - You can predict clone addresses using the factory before deployment
- Tag metadata is shared across tokens via
setUriTag() - License tokens must be owned by organization admins before deploying tags if
_isActiveLicense = true
Developer Tips
- Fill
CollectionConfig.tsfor contract arguments - Use
InstanceFactoryProvider.ts,InstanceTagProvider.ts, etc. to dynamically bind contract instances in tests - Each organization and group is identified by a
bytes32 ID(derived viakeccak256(utf8("ORG1"))) - All tests are located in
test/index.ts