An enterprise-grade ERC-20 style token contract built with ink! v5.1.1, featuring advanced security controls, administrative functions, and comprehensive token management capabilities.
This token contract implements a complete ERC-20 style token with enterprise features:
- Core Functionality: Transfer, approve, allowance operations
- Burn Mechanism: Users can burn their own tokens
- Pausable: Emergency pause functionality for security
- Blacklist: Address blacklisting capability
- Batch Operations: Multi-recipient transfers
- Owner Controls: Administrative functions
- Standard Token Operations: Transfer, approve, allowance
- Burn Functionality: Token destruction with supply reduction
- Pause/Unpause: Emergency stop mechanism
- Blacklist Management: Address restriction system
- Batch Transfers: Efficient multi-recipient operations
- Owner Controls: Administrative oversight
pub struct Token {
total_supply: Balance, // Total token supply
balances: Mapping<AccountId, Balance>, // User balances
allowances: Mapping<(AccountId, AccountId), Balance>, // Allowances
owner: AccountId, // Contract owner
paused: bool, // Pause state
blacklist: Mapping<AccountId, bool>, // Blacklisted addresses
}- Transfer: Move tokens between accounts
- Approve: Authorize spending by another account
- Transfer From: Spend tokens on behalf of another account
- Allowance: Check authorized spending amount
- Balance Of: Query account balance
- Total Supply: Get total token supply
- Burn: Destroy tokens and reduce supply
- Pause/Unpause: Emergency stop mechanism
- Blacklist: Restrict specific addresses
- Batch Transfer: Send to multiple recipients
- Owner Controls: Administrative functions
- Pausable: Emergency stop for security incidents
- Blacklist: Prevent malicious addresses from transacting
- Access Control: Owner-only administrative functions
- Safe Arithmetic: Overflow/underflow protection
- Input Validation: Comprehensive parameter checking
# Development build
cargo contract build
# Production build
cargo contract build --release# Deploy with initial supply
cargo contract instantiate --constructor new --args 1000000 --suri //Alice --skip-confirm// Transfer tokens
transfer(to: AccountId, value: Balance) -> Result<()>
// Approve spending
approve(spender: AccountId, value: Balance) -> Result<()>
// Transfer from (using allowance)
transfer_from(from: AccountId, to: AccountId, value: Balance) -> Result<()>
// Check balance
balance_of(owner: AccountId) -> Balance
// Check allowance
allowance(owner: AccountId, spender: AccountId) -> Balance
// Get total supply
total_supply() -> Balance// Burn tokens
burn(value: Balance) -> Result<()>
// Pause contract (owner only)
pause() -> Result<()>
// Unpause contract (owner only)
unpause() -> Result<()>
// Check if paused
is_paused() -> bool// Add to blacklist (owner only)
blacklist_address(account: AccountId) -> Result<()>
// Remove from blacklist (owner only)
remove_from_blacklist(account: AccountId) -> Result<()>
// Check if blacklisted
is_blacklisted(account: AccountId) -> bool// Transfer to multiple recipients
batch_transfer(recipients: Vec<(AccountId, Balance)>) -> Result<()>cargo testThe contract includes comprehensive tests covering:
- Standard token operations
- Burn functionality
- Pause/unpause mechanisms
- Blacklist operations
- Batch transfers
- Access control
- Error conditions
- Edge cases
The contract emits events for all major operations:
// Token transfers
Transfer { from: Option<AccountId>, to: Option<AccountId>, value: Balance }
// Approvals
Approval { owner: AccountId, spender: AccountId, value: Balance }
// Token burning
Burn { from: AccountId, value: Balance }
// Pause state changes
Paused { by: AccountId }
Unpaused { by: AccountId }
// Blacklist changes
Blacklisted { account: AccountId }
RemovedFromBlacklist { account: AccountId }[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"] }- Lending Protocols: Collateral tokens
- DEX Trading: Trading pairs
- Staking: Reward tokens
- Yield Farming: Farm tokens
- Corporate Tokens: Internal company tokens
- Loyalty Programs: Customer reward systems
- Asset Tokenization: Real-world asset representation
- Payment Systems: Digital payment tokens
- Compliance: Regulatory compliance features
- Access Control: Administrative oversight
- Emergency Response: Pause functionality
- Risk Management: Blacklist capabilities
- Pausable: Emergency stop mechanism
- Blacklist: Address restriction system
- Access Control: Owner-only functions
- Safe Arithmetic: Overflow protection
- Input Validation: Parameter checking
- Event Logging: Full transparency
- All administrative functions are owner-only
- Pause mechanism for emergency situations
- Blacklist for malicious address prevention
- Comprehensive event logging
- Safe arithmetic operations
- Input validation on all functions
- Efficient mapping-based storage
- Minimal data duplication
- Optimized struct layout
- Batch operations for multiple transfers
- Minimal storage writes
- Efficient data structures
- Optimized function implementations
- Pause/Unpause: Emergency stop mechanism
- Blacklist Management: Address restriction
- Contract Ownership: Administrative oversight
- Security Incident: Use
pause()to stop all transfers - Malicious Address: Use
blacklist_address()to restrict - Recovery: Use
unpause()andremove_from_blacklist()to restore
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is provided as-is for educational purposes. Check the main repository for licensing information.
For issues and questions:
- Create an issue in the repository
- Check the main README for troubleshooting
- Review the ink! documentation
π¦ Built with Rust + ink! v5.1.1
This advanced token contract demonstrates enterprise-grade smart contract development patterns and serves as a foundation for building secure, feature-rich token systems.
