{"id":13762025,"url":"https://github.com/near-examples/FT","last_synced_at":"2025-05-10T14:31:07.880Z","repository":{"id":37399745,"uuid":"266784251","full_name":"near-examples/FT","owner":"near-examples","description":"Example implementations of money-like tokens, where one token is the same as any other, using the NEP-141 spec (similar to ERC-20)","archived":false,"fork":false,"pushed_at":"2024-03-25T12:19:37.000Z","size":1019,"stargazers_count":119,"open_issues_count":8,"forks_count":97,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-03-25T14:14:11.117Z","etag":null,"topics":["cli","ready-to-use","rust"],"latest_commit_sha":null,"homepage":"https://github.com/nearprotocol/NEPs/blob/master/specs/Standards/Tokens/FungibleToken.md","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/near-examples.png","metadata":{"files":{"readme":"README-Windows.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-25T13:18:59.000Z","updated_at":"2024-08-03T14:05:16.890Z","dependencies_parsed_at":"2024-08-03T14:05:01.260Z","dependency_job_id":null,"html_url":"https://github.com/near-examples/FT","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near-examples%2FFT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near-examples%2FFT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near-examples%2FFT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near-examples%2FFT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/near-examples","download_url":"https://codeload.github.com/near-examples/FT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224970216,"owners_count":17400292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","ready-to-use","rust"],"created_at":"2024-08-03T14:00:33.756Z","updated_at":"2024-11-16T20:30:56.713Z","avatar_url":"https://github.com/near-examples.png","language":"Rust","readme":"Fungible Token (FT)\n===================\n\nExample implementation of a [Fungible Token] contract which uses [near-contract-standards] and [simulation] tests. This is a contract-only example.\n\n**Note**: this README is specific to Windows and this example. For development on OS X or Linux, please see [README.md](README.md).\n\n  [Fungible Token]: https://nomicon.io/Standards/Tokens/FungibleTokenCore.html\n  [near-contract-standards]: https://github.com/near/near-sdk-rs/tree/master/near-contract-standards\n  [simulation]: https://github.com/near/near-sdk-rs/tree/master/near-sdk-sim\n\nPrerequisites\n=============\n\nIf you're using Gitpod, you can skip this step.\n\n1. Make sure Rust is installed per the prerequisites in [`near-sdk-rs`](https://github.com/near/near-sdk-rs#pre-requisites)\n2. Ensure `near-cli` is installed by running `near --version`. If not installed, install with: `npm install --global near-cli`\n\n## Building\n\nTo build run in CMD:\n```bash\nbuild.bat\n```\n\nUsing this contract\n===================\n\nThis smart contract will get deployed to your NEAR account. For this example, please create a new NEAR account. Because NEAR allows the ability to upgrade contracts on the same account, initialization functions must be cleared. If you'd like to run this example on a NEAR account that has had prior contracts deployed, please use the `near-cli` command `near delete`, and then recreate it in Wallet. To create (or recreate) an account, please follow the directions on [NEAR Wallet](https://wallet.near.org/).\n\nSwitch to `mainnet`. You can skip this step to use `testnet` as a default network.\n\n    set NEAR_ENV=mainnet\n\nIn the project root, log in to your newly created account  with `near-cli` by following the instructions after this command:\n\n    near login\n\nTo make this tutorial easier to copy/paste, we're going to set an environment variable for your account id. In the below command, replace `MY_ACCOUNT_NAME` with the account name you just logged in with, including the `.near`:\n\n    set ID=MY_ACCOUNT_NAME\n\nYou can tell if the environment variable is set correctly if your command line prints the account name after this command:\n\n    echo %ID%\n\nNow we can deploy the compiled contract in this example to your account:\n\n    near deploy --wasmFile res/fungible_token.wasm --accountId %ID%\n\nFT contract should be initialized before usage. You can read more about metadata at ['nomicon.io'](https://nomicon.io/Standards/FungibleToken/Metadata.html#reference-level-explanation). Modify the parameters and create a token:\n\n    near call %ID% new \"{\\\"owner_id\\\": \\\"\"%ID%\"\\\", \\\"total_supply\\\": \\\"1000000000000000\\\", \\\"metadata\\\": { \\\"spec\\\": \\\"ft-1.0.0\\\", \\\"name\\\": \\\"Example Token Name\\\", \\\"symbol\\\": \\\"EXLT\\\", \\\"decimals\\\": 8 }}\" --accountId %ID%\n\nGet metadata:\n\n    near view %ID% ft_metadata\n\n\nTransfer Example\n---------------\n\nLet's set up an account to transfer some tokens to. These account will be a sub-account of the NEAR account you logged in with.\n\n    near create-account bob.%ID% --masterAccount %ID% --initialBalance 1\n\nAdd storage deposit for Bob's account:\n\n    near call %ID% storage_deposit '' --accountId bob.%ID% --amount 0.00125\n\nCheck balance of Bob's account, it should be `0` for now:\n\n    near view %ID% ft_balance_of \"{\\\"account_id\\\": \\\"\"bob.%ID%\"\\\"}\"\n\nTransfer tokens to Bob from the contract that minted these fungible tokens, exactly 1 yoctoNEAR of deposit should be attached:\n\n    near call %ID% ft_transfer \"{\\\"receiver_id\\\": \\\"\"bob.%ID%\"\\\", \\\"amount\\\": \\\"19\\\"}\" --accountId %ID% --amount 0.000000000000000000000001\n\n\nCheck the balance of Bob again with the command from before and it will now return `19`.\n\n## Testing\n\nAs with many Rust libraries and contracts, there are tests in the main fungible token implementation at `ft/src/lib.rs`.\n\nAdditionally, this project has [simulation] tests in `tests/sim`. Simulation tests allow testing cross-contract calls, which is crucial to ensuring that the `ft_transfer_call` function works properly. These simulation tests are the reason this project has the file structure it does. Note that the root project has a `Cargo.toml` which sets it up as a workspace. `ft` and `test-contract-defi` are both small \u0026 focused contract projects, the latter only existing for simulation tests. The root project imports `near-sdk-sim` and tests interaction between these contracts.\n\nYou can run all these tests with one command:\n\n```bash\ncargo test\n```\n\nIf you want to run only simulation tests, you can use `cargo test simulate`, since all the simulation tests include \"simulate\" in their names.\n\n\n## Notes\n\n - The maximum balance value is limited by U128 (`2**128 - 1`).\n - JSON calls should pass U128 as a base-10 string. E.g. \"100\".\n - This does not include escrow functionality, as `ft_transfer_call` provides a superior approach. An escrow system can, of course, be added as a separate contract or additional functionality within this contract.\n\n## No AssemblyScript?\n\n[near-contract-standards] is currently Rust-only. We strongly suggest using this library to create your own Fungible Token contract to ensure it works as expected.\n\nSomeday NEAR core or community contributors may provide a similar library for AssemblyScript, at which point this example will be updated to include both a Rust and AssemblyScript version.\n\n## Contributing\n\nWhen making changes to the files in `ft` or `test-contract-defi`, remember to use `./build.sh` to compile all contracts and copy the output to the `res` folder. If you forget this, **the simulation tests will not use the latest versions**.\n","funding_links":[],"categories":["Projects"],"sub_categories":["FT"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnear-examples%2FFT","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnear-examples%2FFT","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnear-examples%2FFT/lists"}