{"id":23193446,"url":"https://github.com/william-versatile/near-smart-contract","last_synced_at":"2025-04-05T07:25:38.682Z","repository":{"id":225576530,"uuid":"765944589","full_name":"William-versatile/near-smart-contract","owner":"William-versatile","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-01T23:42:26.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T15:17:05.639Z","etag":null,"topics":["nearprotocol","rust","smart-contracts"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/William-versatile.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-03-01T23:41:26.000Z","updated_at":"2024-03-01T23:47:14.000Z","dependencies_parsed_at":"2024-03-03T01:42:13.945Z","dependency_job_id":null,"html_url":"https://github.com/William-versatile/near-smart-contract","commit_stats":null,"previous_names":["william-xfactor/near-smart-contract","william-versatile/near-smart-contract"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/William-versatile%2Fnear-smart-contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/William-versatile%2Fnear-smart-contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/William-versatile%2Fnear-smart-contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/William-versatile%2Fnear-smart-contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/William-versatile","download_url":"https://codeload.github.com/William-versatile/near-smart-contract/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247302161,"owners_count":20916645,"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":["nearprotocol","rust","smart-contracts"],"created_at":"2024-12-18T13:11:33.160Z","updated_at":"2025-04-05T07:25:38.661Z","avatar_url":"https://github.com/William-versatile.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Non-fungible Token (NFT)\n===================\n\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/near-examples/NFT)\n\n\nThis repository includes an example implementation of a [non-fungible token] contract which uses [near-contract-standards] and [simulation] tests.\n\n  [non-fungible token]: https://nomicon.io/Standards/NonFungibleToken/README.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\nPrerequisites\n=============\nIf you're using Gitpod, you can skip this step.\n\n  * Make sure Rust is installed per the prerequisites in [`near-sdk-rs`](https://github.com/near/near-sdk-rs).\n  * Make sure [near-cli](https://github.com/near/near-cli) is installed.\n\nExplore this contract\n=====================\n\nThe source for this contract is in `nft/src/lib.rs`. It provides methods to manage access to tokens, transfer tokens, check access, and get token owner. Note, some further exploration inside the rust macros is needed to see how the `NonFungibleToken` contract is implemented.\n\nBuilding this contract\n======================\nRun the following, and we'll build our rust project up via cargo. This will generate our WASM binaries into our `res/` directory. This is the smart contract we'll be deploying onto the NEAR blockchain later.\n```bash\n./build.sh\n```\n\nTesting this contract\n=====================\nWe have some tests that you can run. For example, the following will run our simple tests to verify that our contract code is working.\n```bash\ncargo test -- --nocapture\n```\nThe more complex simulation tests aren't run with this command, but we can find them in `tests/sim`.\n\nUsing this contract\n===================\n\n### Quickest deploy\n\nYou can build and deploy this smart contract to a development account. [Dev Accounts](https://docs.near.org/docs/concepts/account#dev-accounts) are auto-generated accounts to assist in developing and testing smart contracts. Please see the [Standard deploy](#standard-deploy) section for creating a more personalized account to deploy to.\n\n```bash\nnear dev-deploy --wasmFile res/non_fungible_token.wasm\n```\n\nBehind the scenes, this is creating an account and deploying a contract to it. On the console, notice a message like:\n\n\u003eDone deploying to dev-1234567890123\n\nIn this instance, the account is `dev-1234567890123`. A file has been created containing a key pair to\nthe account, located at `neardev/dev-account`. To make the next few steps easier, we're going to set an\nenvironment variable containing this development account id and use that when copy/pasting commands.\nRun this command to set the environment variable:\n\n```bash\nsource neardev/dev-account.env\n```\n\nYou can tell if the environment variable is set correctly if your command line prints the account name after this command:\n```bash\necho $CONTRACT_NAME\n```\n\nThe next command will initialize the contract using the `new` method:\n\n```bash\nnear call $CONTRACT_NAME new_default_meta '{\"owner_id\": \"'$CONTRACT_NAME'\"}' --accountId $CONTRACT_NAME\n```\n\nTo view the NFT metadata:\n\n```bash\nnear view $CONTRACT_NAME nft_metadata\n```\n\n### Standard deploy\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 in [Test Wallet](https://wallet.testnet.near.org) or ([NEAR Wallet](https://wallet.near.org/) if we're using `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 our account id. In the below command, replace `MY_ACCOUNT_NAME` with the account name we just logged in with, including the `.testnet` (or `.near` for `mainnet`):\n\n    ID=MY_ACCOUNT_NAME\n\nWe can tell if the environment variable is set correctly if our 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/non_fungible_token.wasm --accountId $ID\n\nNFT contract should be initialized before usage. More info about the metadata at [nomicon.io](https://nomicon.io/Standards/NonFungibleToken/Metadata.html). But for now, we'll initialize with the default metadata.\n\n    near call $ID new_default_meta '{\"owner_id\": \"'$ID'\"}' --accountId $ID\n\nWe'll be able to view our metadata right after:\n\n    near view $ID nft_metadata\n\nThen, let's mint our first token. This will create a NFT based on Olympus Mons where only one copy exists:\n\n    near call $ID nft_mint '{\"token_id\": \"0\", \"receiver_id\": \"'$ID'\", \"token_metadata\": { \"title\": \"Olympus Mons\", \"description\": \"Tallest mountain in charted solar system\", \"media\": \"https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Olympus_Mons_alt.jpg/1024px-Olympus_Mons_alt.jpg\", \"copies\": 1}}' --accountId $ID --deposit 0.1\n\nTransferring our NFT\n====================\n\nLet's set up an account to transfer our freshly minted token to. This account will be a sub-account of the NEAR account we logged in with originally via `near login`.\n\n    near create-account alice.$ID --masterAccount $ID --initialBalance 10\n\nChecking Alice's account for tokens:\n\n    near view $ID nft_tokens_for_owner '{\"account_id\": \"'alice.$ID'\"}'\n\nThen we'll transfer over the NFT into Alice's account. Exactly 1 yoctoNEAR of deposit should be attached:\n\n    near call $ID nft_transfer '{\"token_id\": \"0\", \"receiver_id\": \"alice.'$ID'\", \"memo\": \"transfer ownership\"}' --accountId $ID --depositYocto 1\n\nChecking Alice's account again shows us that she has the Olympus Mons token.\n\nNotes\n=====\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\nAssemblyScript\n==============\nCurrently, AssemblyScript is not supported for this example. An old version can be found in the [NEP4 example](https://github.com/near-examples/NFT/releases/tag/nep4-example), but this is not recommended as it is out of date and does not follow the standards the NEAR SDK has set currently.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliam-versatile%2Fnear-smart-contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliam-versatile%2Fnear-smart-contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliam-versatile%2Fnear-smart-contract/lists"}