{"id":13746445,"url":"https://github.com/near/near-sdk-rs","last_synced_at":"2026-05-26T23:01:02.019Z","repository":{"id":37051635,"uuid":"190815700","full_name":"near/near-sdk-rs","owner":"near","description":"Rust library for writing NEAR smart contracts","archived":false,"fork":false,"pushed_at":"2026-05-26T01:11:12.000Z","size":28633,"stargazers_count":507,"open_issues_count":98,"forks_count":276,"subscribers_count":14,"default_branch":"master","last_synced_at":"2026-05-26T03:12:52.615Z","etag":null,"topics":["blockchain","nearprotocol","rust","sdk","wasm"],"latest_commit_sha":null,"homepage":"https://docs.near.org/build/smart-contracts/what-is","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/near.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-06-07T22:08:29.000Z","updated_at":"2026-05-07T01:20:45.000Z","dependencies_parsed_at":"2026-04-06T22:02:42.590Z","dependency_job_id":null,"html_url":"https://github.com/near/near-sdk-rs","commit_stats":{"total_commits":828,"total_committers":65,"mean_commits":"12.738461538461538","dds":0.6123188405797102,"last_synced_commit":"73f41dadcd0320d3a11f13af0e7c6611afca8e5d"},"previous_names":["nearprotocol/near-bindgen"],"tags_count":159,"template":false,"template_full_name":null,"purl":"pkg:github/near/near-sdk-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-sdk-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-sdk-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-sdk-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-sdk-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/near","download_url":"https://codeload.github.com/near/near-sdk-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-sdk-rs/sbom","scorecard":{"id":441480,"data":{"date":"2025-08-11","repo":{"name":"github.com/near/near-sdk-rs","commit":"93ebb5f0c4d35bdb44774828cefe18385cf3a9a8"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":6.3,"checks":[{"name":"Code-Review","score":8,"reason":"Found 26/30 approved changesets -- score normalized to 8","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":10,"reason":"14 commit(s) and 7 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/add-to-devtools.yml:1","Warn: no topLevel permission defined: .github/workflows/compare_sizes.yml:1","Warn: no topLevel permission defined: .github/workflows/coverage.yml:1","Warn: topLevel 'contents' permission set to 'write': .github/workflows/release-plz.yml:5","Warn: no topLevel permission defined: .github/workflows/test.yml:1","Warn: no topLevel permission defined: .github/workflows/test_examples.yml:1","Warn: no topLevel permission defined: .github/workflows/test_examples_small.yml:1","Warn: no topLevel permission defined: .github/workflows/typo.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE-APACHE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE-APACHE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/add-to-devtools.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/add-to-devtools.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/compare_sizes.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/compare_sizes.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/compare_sizes.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/compare_sizes.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/compare_sizes.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/compare_sizes.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/coverage.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/coverage.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/coverage.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/coverage.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/coverage.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/coverage.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release-plz.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/release-plz.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release-plz.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/release-plz.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release-plz.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/release-plz.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:68: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:73: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:80: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:82: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:88: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:99: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:101: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:106: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:118: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:120: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test_examples.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test_examples.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test_examples.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test_examples.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test_examples.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test_examples.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test_examples_small.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test_examples_small.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test_examples_small.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test_examples_small.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test_examples_small.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/test_examples_small.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/typo.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/typo.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/typo.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/near/near-sdk-rs/typo.yml/master?enable=pin","Warn: containerImage not pinned by hash: contract-builder/Dockerfile:1: pin your Docker image by updating rust:1.73.0 to rust:1.73.0@sha256:25fa7a9aa4dadf6a466373822009b5361685604dbe151b030182301f1a3c2f58","Warn: downloadThenRun not pinned by hash: .github/workflows/compare_sizes.yml:21","Warn: pipCommand not pinned by hash: .github/workflows/compare_sizes.yml:23","Warn: downloadThenRun not pinned by hash: .github/workflows/coverage.yml:49","Warn: downloadThenRun not pinned by hash: .github/workflows/test.yml:37","Warn: downloadThenRun not pinned by hash: .github/workflows/test_examples.yml:39","Warn: downloadThenRun not pinned by hash: .github/workflows/test_examples_small.yml:35","Info:   0 out of  15 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of  20 third-party GitHubAction dependencies pinned","Info:   0 out of   1 containerImage dependencies pinned","Info:   0 out of   5 downloadThenRun dependencies pinned","Info:   0 out of   1 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/near/.github/SECURITY.MD:1","Info: Found linked content: github.com/near/.github/SECURITY.MD:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/near/.github/SECURITY.MD:1","Info: Found text in security policy: github.com/near/.github/SECURITY.MD:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 28 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T05:41:02.188Z","repository_id":37051635,"created_at":"2025-08-19T05:41:02.188Z","updated_at":"2025-08-19T05:41:02.188Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33542350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["blockchain","nearprotocol","rust","sdk","wasm"],"created_at":"2024-08-03T06:00:53.719Z","updated_at":"2026-05-26T23:01:01.980Z","avatar_url":"https://github.com/near.png","language":"Rust","funding_links":[],"categories":["Web3 and ZKP Framework","Libraries / Frameworks","Smart Contract Platforms"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n  \u003ch1\u003e\u003ccode\u003enear-sdk\u003c/code\u003e\u003c/h1\u003e\n\n  \u003cp\u003e\n    \u003cstrong\u003eRust library for writing NEAR smart contracts.\u003c/strong\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    Previously known as \u003ccode\u003enear-bindgen\u003c/code\u003e.\n  \u003c/p\u003e\n  \u003cp\u003e\n      Maximum supported Rust version is \u003cstrong\u003e1.86.0\u003c/strong\u003e\n  \u003c/p\u003e\n\n\n  \u003cp\u003e\n    \u003ca href=\"https://docs.rs/near-sdk\"\u003e\u003cimg src=\"https://docs.rs/near-sdk/badge.svg?style=flat-square\" alt=\"Reference Documentation\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://blog.rust-lang.org/2025/04/03/Rust-1.86.0/\"\u003e\u003cimg src=\"https://img.shields.io/badge/rustc-1.86-lightgray.svg?style=flat-square\" alt=\"MSRV\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/near-sdk\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/near-sdk.svg?style=flat-square\" alt=\"Crates.io version\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/near-sdk\"\u003e\u003cimg src=\"https://img.shields.io/crates/d/near-sdk.svg?style=flat-square\" alt=\"Download\" /\u003e\u003c/a\u003e\n    \u003ca href=\"http://near.chat\"\u003e\u003cimg src=\"https://img.shields.io/discord/490367152054992913?style=flat-square\u0026label=discord\u0026color=lightgreen\" alt=\"Join the community on Discord\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://t.me/NEAR_Tools_Community_Group\"\u003e\u003cimg src=\"https://img.shields.io/badge/telegram-online-lightgreen?style=flat-square\" alt=\"Join the community on Telegram\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://x.com/nearprotocol\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/NEARProtocol\" alt=\"Join the community on Twitter\" /\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\n   \u003ch3\u003e\n      \u003ca href=\"https://github.com/near/near-sdk-rs#features\"\u003eFeatures\u003c/a\u003e\n      \u003cspan\u003e | \u003c/span\u003e\n      \u003ca href=\"https://github.com/near/near-sdk-rs#pre-requisites\"\u003ePre-requisites\u003c/a\u003e\n      \u003cspan\u003e | \u003c/span\u003e\n      \u003ca href=\"https://github.com/near/near-sdk-rs#writing-rust-contract\"\u003eWriting Rust Contract\u003c/a\u003e\n      \u003cspan\u003e | \u003c/span\u003e\n      \u003ca href=\"https://github.com/near/near-sdk-rs#building-rust-contract\"\u003eBuilding Rust Contract\u003c/a\u003e\n      \u003cspan\u003e | \u003c/span\u003e\n      \u003ca href=\"https://docs.rs/near-sdk\"\u003eReference Documentation\u003c/a\u003e\n      \u003cspan\u003e | \u003c/span\u003e\n      \u003ca href=\"https://github.com/near/near-sdk-rs#contributing\"\u003eContributing\u003c/a\u003e\n    \u003c/h3\u003e\n\u003c/div\u003e\n\n## Release notes\n\n**Release notes and unreleased changes can be found in the [CHANGELOG](https://github.com/near/near-sdk-rs/blob/master/CHANGELOG.md)**\n\n## Example\n\nWrap a struct in `#[near]` and it generates a smart contract compatible with the NEAR blockchain:\n```rust\nuse near_sdk::{near, env};\n\n#[near(contract_state)]\n#[derive(Default)]\npub struct StatusMessage {\n    records: HashMap\u003cAccountId, String\u003e,\n}\n\n#[near]\nimpl StatusMessage {\n    pub fn set_status(\u0026mut self, message: String) {\n        let account_id = env::signer_account_id();\n        self.records.insert(account_id, message);\n    }\n\n    pub fn get_status(\u0026self, account_id: AccountId) -\u003e Option\u003cString\u003e {\n        self.records.get(\u0026account_id).cloned()\n    }\n}\n```\n\nFor more information, see the Attribute Macro [`near`](https://docs.rs/near-sdk/latest/near_sdk/attr.near.html) documentation.\n\n[![How to Deploy a Smart Contract on NEAR | Full Guide for Windows, Mac \u0026 Linux (Step-by-Step)](https://github.com/user-attachments/assets/c40daffd-6023-437a-ad2e-f8ab2d2206a9)](https://www.youtube.com/watch?v=7RgQEQSwPjc)\n\n## Github Codespaces template + [an online ide](https://docs.github.com/en/codespaces/reference/using-the-vs-code-command-palette-in-codespaces)\n\n* Quick start your project with the [template repository](https://github.com/near/cargo-near-new-project-template) generated by `cargo near new` command\n* The associated [template repository](https://github.com/near/cargo-near-new-project-template)'s README contains a `Code \u003e Codespaces \u003e Create codespace on main` screenshot.\n* Clicking the button will result in using [Github Codespaces devcontainer](https://docs.github.com/en/codespaces). The containers allow you to start building without the need to install any dependencies on your machine and provide the actual version.\n\n## Features\n\n### Unit-testable\nWriting unit tests is easy with `near-sdk`:\n\n```rust\n#[test]\nfn set_get_message() {\n    let mut contract = StatusMessage::default();\n    contract.set_status(\"hello\".to_string());\n    assert_eq!(\"hello\".to_string(), contract.get_status(\"bob_near\".to_string()).unwrap());\n}\n```\n\nRun unit test the usual way:\n```sh\ncargo test --package status-message\n```\n\n### Asynchronous cross-contract calls\nAsynchronous cross-contract calls allow parallel execution of multiple contracts in parallel with subsequent aggregation on another contract. [`env`](https://docs.rs/near-sdk/latest/near_sdk/env/index.html) exposes the following methods:\n* [`promise_create`](https://docs.rs/near-sdk/latest/near_sdk/env/fn.promise_create.html) -- schedules an execution of a function on some contract;\n* [`promise_then`](https://docs.rs/near-sdk/latest/near_sdk/env/fn.promise_then.html) -- attaches the callback back to the current contract once the function is executed;\n* [`promise_and`](https://docs.rs/near-sdk/latest/near_sdk/env/fn.promise_and.html) -- combinator, allows waiting on several promises simultaneously, before executing the callback;\n* [`promise_return`](https://docs.rs/near-sdk/latest/near_sdk/env/fn.promise_return.html) -- treats the result of execution of the promise as the result of the current function.\n\nFollow [examples/cross-contract-high-level](https://github.com/near/near-sdk-rs/tree/master/examples/cross-contract-calls/high-level)\nto see various usages of cross contract calls, including **system-level actions** done from inside the contract like balance transfer (examples of other system-level actions are: account creation, access key creation/deletion, contract deployment, etc).\n\n### Initialization methods\nWe can define an initialization method that can be used to initialize the state of the contract. `#[init]` verifies that the contract has not been initialized yet (the contract state doesn't exist) and will panic otherwise.\n\n```rust\n#[near]\nimpl StatusMessage {\n    #[init]\n    pub fn new(user: String, status: String) -\u003e Self {\n        let mut res = Self::default();\n        res.records.insert(user, status);\n        res\n    }\n}\n```\n\nEven if you have initialization method your smart contract is still expected to derive `Default` trait. If you don't\nwant to disable default initialization, then you can prohibit it like this:\n```rust\nimpl Default for StatusMessage {\n    fn default() -\u003e Self {\n        near_sdk::env::panic_str(\"Contract should be initialized before the usage.\")\n    }\n}\n```\nYou can also prohibit `Default` trait initialization by using `near_sdk::PanicOnDefault` helper macro. E.g.:\n```rust\n#[near(contract_state)]\n#[derive(PanicOnDefault)]\npub struct StatusMessage {\n    records: HashMap\u003cString, String\u003e,\n}\n```\n\n### Payable methods\nWe can allow methods to accept token transfer together with the function call. This is done so that contracts can define a fee in tokens that needs to be paid when they are used. By the default the methods are not payable and they will panic if someone will attempt to transfer tokens to them during the invocation. This is done for safety reason, in case someone accidentally transfers tokens during the function call.\n\nTo declare a payable method simply use `#[payable]` decorator:\n```rust\n\n#[payable]\npub fn my_method(\u0026mut self) {\n...\n}\n```\n\n### Private methods\nUsually, when a contract has to have a callback for a remote cross-contract call, this callback method should\nonly be called by the contract itself. It's to avoid someone else calling it and messing the state. Pretty common pattern\nis to have an assert that validates that the direct caller (predecessor account ID) matches to the contract's account (current account ID).\nMacro `#[private]` simplifies it, by making it a single line macro instead and improves readability.\n\nTo declare a private method use `#[private]` decorator:\n```rust\n\n#[private]\npub fn my_method(\u0026mut self) {\n...\n}\n/// Which is equivalent to\n\npub fn my_method(\u0026mut self ) {\n    if near_sdk::env::current_account_id() != near_sdk::env::predecessor_account_id() {\n        near_sdk::env::panic_str(\"Method my_method is private\");\n    }\n...\n}\n```\n\nNow, only the account of the contract itself can call this method, either directly or through a promise.\n\n## Pre-requisites\nTo develop Rust contracts you would need to:\n* Install [Rustup](https://rustup.rs/):\n```sh\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n```\n* Add wasm target to your toolchain:\n```sh\nrustup target add wasm32-unknown-unknown\n```\n\n## Writing Rust Contract\nYou can follow the [examples/status-message](https://github.com/near/near-sdk-rs/tree/master/examples/status-message) crate that shows a simple Rust contract.\n\nThe general workflow is the following:\n1. Create a crate and configure the `Cargo.toml` similarly to how it is configured in [examples/status-message/Cargo.toml](https://github.com/near/near-sdk-rs/tree/master/examples/status-message/Cargo.toml);\n2. Crate needs to have one `pub` struct that will represent the smart contract itself:\n    * The struct needs to implement `Default` trait which\n    NEAR will use to create the initial state of the contract upon its first usage;\n\n   Here is an example of a smart contract struct:\n   ```rust\n   use near_sdk::{near, env};\n\n   #[near(contract_state)]\n   #[derive(Default)]\n   pub struct MyContract {\n       data: HashMap\u003cu64, u64\u003e\n   }\n   ```\n\n3. Define methods that NEAR will expose as smart contract methods:\n    * You are free to define any methods for the struct but only public methods will be exposed as smart contract methods;\n    * Methods need to use either `\u0026self`, `\u0026mut self`, or `self`;\n    * Decorate the `impl` section with `#[near]` macro. That is where all the M.A.G.I.C. (Macros-Auto-Generated Injected Code) happens;\n    * If you need to use blockchain interface, e.g. to get the current account id then you can access it with `env::*`;\n\n    Here is an example of smart contract methods:\n    ```rust\n    #[near]\n    impl MyContract {\n        pub fn insert_data(\u0026mut self, key: u64, value: u64) -\u003e Option\u003cu64\u003e {\n            self.data.insert(key)\n        }\n        pub fn get_data(\u0026self, key: u64) -\u003e Option\u003cu64\u003e {\n            self.data.get(\u0026key).cloned()\n        }\n    }\n    ```\n\n## Building Rust Contract\n\n### [cargo-near](https://github.com/near/cargo-near)\n\n`cargo-near` is an easy and recommended way to build and deploy Rust contracts.\n\n#### Installation\n\n\u003cdetails\u003e\n  \u003csummary\u003eInstall prebuilt binaries via shell script (Linux, macOS)\u003c/summary\u003e\n\n```sh\ncurl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eInstall prebuilt binaries via powershell script (Windows)\u003c/summary\u003e\n\n```sh\nirm https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.ps1 | iex\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eInstall prebuilt binaries into your Node.js application\u003c/summary\u003e\n\n```sh\nnpm install cargo-near\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eCompile and install from source code (Cargo)\u003c/summary\u003e\n\n```sh\ncargo install cargo-near\n```\n\nor, install the most recent version from git repository:\n\n```sh\n$ git clone https://github.com/near/cargo-near\n$ cargo install --path cargo-near\n```\n\u003c/details\u003e\n\n#### Usage\n\nSee `cargo near --help` for a complete list of available commands or run `cargo near` to dive into interactive mode.\nHelp is also available for each individual command with a `--help` flag, e.g. `cargo near build --help`.\n\n```sh\ncargo near\n```\n\nStarts interactive mode that will allow to explore all the available commands.\n\n```sh\ncargo near build\n```\n\nBuilds a NEAR smart contract along with its [ABI](https://github.com/near/abi) (while in the directory containing contract's Cargo.toml).\n\nIf you have problems/errors with schema/ABI during build that you cannot figure out quick, you can skip/circumvent them with:\n\n```sh\ncargo near build non-reproducible-wasm --no-abi\n```\n\nAnd return to figuring how to resolve problems with generating ABI of your contract later.\n\n```sh\ncargo near create-dev-account\n```\n\nGuides you through creation of a new NEAR account on [testnet](https://explorer.testnet.near.org).\n\n```sh\ncargo near deploy\n```\n\nBuilds the smart contract (equivalent to `cargo near build`) and guides you to deploy it to the blockchain.\n\n## NEAR contract standards\n\n[`near-contract-standards` crate](https://github.com/near/near-sdk-rs/tree/master/near-contract-standards) provides a set of interfaces and implementations for NEAR's contract standards:\n\n- Upgradability\n- Fungible Token (NEP-141). See [example usage](https://github.com/near/near-sdk-rs/tree/master/examples/fungible-token)\n- Non-Fungible Token (NEP-171). See [example usage](https://github.com/near/near-sdk-rs/tree/master/examples/non-fungible-token)\n\n\n## Versioning\n\n### Semantic Versioning\n\nThis crate follows [Cargo's semver guidelines](https://doc.rust-lang.org/cargo/reference/semver.html).\n\nState breaking changes (low-level serialization format of any data type) will be avoided at all costs. If a change like this were to happen, it would come with a major version and come with a compiler error. If you encounter one that does not, [open an issue](https://github.com/near/near-sdk-rs/issues/new)!\n\n### MSRV\n\nThe minimum supported Rust version is currently `1.86`. There are no guarantees that this will be upheld if a security patch release needs to come in that requires a Rust toolchain increase.\n\n## Contributing\n\nIf you are interested in contributing, please look at the [contributing guidelines](https://github.com/near/near-sdk-rs/blob/master/CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnear%2Fnear-sdk-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnear%2Fnear-sdk-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnear%2Fnear-sdk-rs/lists"}