Loading…
Loading…
An Animica smart-contract tip jar: anyone can tip, only the owner can withdraw. This preview simulates the contract locally — on-chain deploy and settlement are prepared for the next phase.
Language: Animica vm_py (Python)
Contract deployment is prepared for Animica testnet; live wallet-signed deployment connects in the next phase. Forge never executes contract code on the server.
# Tip Jar — Animica smart contract (vm_py / animica-python)
#
# A minimal on-chain tip jar: anyone can tip, only the owner can withdraw.
# Amounts are integer base units (nANM). This is a template — deploy and the
# real value transfer in withdraw() is wired to the Animica VM. In the current
# Forge phase the transfer is a MOCK (see the commented line below).
from animica import contract, public, view, msg, transfer
@contract
class TipJar:
def __init__(self):
# The account that deployed the contract owns it and can withdraw.
self.owner = msg.sender
# Running total of everything ever tipped (base units, nANM).
self.total = 0
# Current withdrawable balance held by the jar (base units, nANM).
self.balance = 0
# Ordered, de-duplicated list of addresses that have tipped.
self._tippers = []
# Per-address tip totals, for a simple leaderboard.
self._by_sender = {}
@public
def tip(self, amount):
"""Add a tip. Records the sender and grows the running total."""
assert amount > 0, "tip amount must be positive"
sender = msg.sender
if sender not in self._by_sender:
self._tippers.append(sender)
self._by_sender[sender] = 0
self._by_sender[sender] += amount
self.total += amount
self.balance += amount
return self.total
@view
def total_tips(self):
"""Total value tipped over the lifetime of the jar (base units)."""
return self.total
@view
def tippers(self):
"""Every address that has tipped, in first-tip order."""
return self._tippers
@view
def tipped_by(self, who):
"""How much a single address has tipped (base units)."""
return self._by_sender.get(who, 0)
@public
def withdraw(self):
"""Owner-only. Zeroes the jar and sends the balance to the owner."""
assert msg.sender == self.owner, "only the owner can withdraw"
amount = self.balance
assert amount > 0, "nothing to withdraw"
self.balance = 0
# MOCK (prepared for the next phase): the real value transfer runs on
# deploy against the Animica VM. Uncomment when settlement is live.
# transfer(self.owner, amount)
return amount
A mintable ANM20 fungible token contract in Animica vm_py, with an offline dapp UI that simulates transfer and owner-only mint. Deployment is prepared for Animica testnet.