Building with Solidity

7. Mint, Spend, Lock, Send

Recognize and implement common state‑changing patterns (minting, spending, locking, sending) in Solidity on VeChainThor.

Prerequisites

Common On‑Chain Actions

Smart contracts are like tiny economies—they mint, spend, lock, and send value.​
In a Focus2Earn‑style contract, minting simply means increasing a stored balance:

// Minting points
users[msg.sender].points += rewardAmount;
// Minting points
users[msg.sender].points += rewardAmount;
// Minting points
users[msg.sender].points += rewardAmount;

No one sends these points manually—they are created by your contract logic when conditions are met.​

Spending is the opposite: you check that a user has enough points, then reduce their balance.

require(users[msg.sender].points >= cost, "Not enough points");
users[msg.sender].points -= cost;
require(users[msg.sender].points >= cost, "Not enough points");
users[msg.sender].points -= cost;
require(users[msg.sender].points >= cost, "Not enough points");
users[msg.sender].points -= cost;

Nice! This pattern is everywhere: games, loyalty apps, and reward systems on VeChain.​

You can also lock actions behind time conditions, like a cooldown:

modifier cooldownPassed() {
    require(
        block.timestamp >= users[msg.sender].lastSession + 5 minutes,
        "Cooldown active"
    );
    _;
}
modifier cooldownPassed() {
    require(
        block.timestamp >= users[msg.sender].lastSession + 5 minutes,
        "Cooldown active"
    );
    _;
}
modifier cooldownPassed() {
    require(
        block.timestamp >= users[msg.sender].lastSession + 5 minutes,
        "Cooldown active"
    );
    _;
}

Think of this like a timer in a game: users must wait before claiming again, enforced entirely on‑chain.​

Finally, sending moves tokens from the contract to users:

token.transfer(msg.sender, rewardAmount);
token.transfer(msg.sender, rewardAmount);
token.transfer(msg.sender, rewardAmount);

You can wire any condition you like before this line: proofs, completions, or verifications.​

Common Pitfalls

Forgetting checks before spending or sending can break invariants and open exploits.

Keep it up, champ! You master how typical dApps use the same four building blocks for rewards, payments, and access control.