In this blog post, we’ll explore a Token Vesting smart contract built using Solidity and deployed on the Conflux eSpace Testnet. The contract is designed to lock tokens for specific beneficiaries for a period of time before they can be claimed. This is useful in scenarios like team allocation, investor token distribution, or ecosystem incentives where tokens should be gradually unlocked rather than fully available at once.
What is Token Vesting?
Token vesting is a mechanism to release tokens over time. Rather than giving someone their entire token allocation up front, a vesting schedule ensures they receive it gradually. This approach is used to align incentives and prevent early dumping of tokens.
TokenLockVault Contract Overview
The TokenLockVault
contract allows an owner to lock tokens on behalf of beneficiaries. The tokens become claimable after a predefined unlock time.
Key Features
- Token Locking: Lock tokens for an address until a future time.
- Claim Functionality: Allows the user to claim their tokens after the unlock time.
- Admin Functions: Only the owner can lock tokens for others.
- ERC-20 Compatible: Works with any standard ERC-20 token.
Smart Contract Functions
1. lockTokens(address beneficiary, uint256 amount, uint256 unlockTime)
Locks a specific amount of tokens for a beneficiary, which they can claim after the unlock time.
2. claimTokens()
Beneficiaries can call this function after the unlock time to receive their tokens.
3. getLockedTokens(address account)
Returns the total locked amount and unlock timestamp for a given user.
How It Works
- Owner approves the vault contract to spend tokens.
-
Owner locks tokens for multiple addresses using the
lockTokens
function. - After the unlock timestamp is reached, users can call
claimTokens()
to receive their tokens. - Tokens remain non-transferable until claimed.
Demo Workflow (Conflux eSpace Testnet)
- Deploy your custom ERC-20 token (e.g.,
MyToken
). - Deploy
TokenLockVault
and pass the token address. - Use
approve
from your token to allowTokenLockVault
to manage the token balance. - Call
lockTokens()
to assign locked tokens to recipients. - After the unlock time, users call
claimTokens()
to receive their allocation.
Smart Contract Code
You can find the full source code here:
- GitHub Repo: TokenLockVault Repository
Video Tutorial
Summary
The TokenLockVault smart contract is a powerful utility for ensuring fair and secure distribution of tokens. By adding time-based locking, it encourages long-term commitment and aligns incentives for teams and communities.
Feel free to fork the repo and modify it for your project needs.
Connect
For any help or collaboration, feel free to reach out on Twitter
Happy Building