{"id":13288223,"url":"https://github.com/derkiner/Near-Deploying-A-Sample-Contract-","last_synced_at":"2025-03-10T05:32:16.130Z","repository":{"id":135936358,"uuid":"482199078","full_name":"derkiner/Near-Deploying-A-Sample-Contract-","owner":"derkiner","description":"This repository includes a complete project structure for AssemblyScript contracts targeting the NEAR platform.","archived":false,"fork":false,"pushed_at":"2022-04-25T16:54:45.000Z","size":1729,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-29T16:58:25.666Z","etag":null,"topics":["assemblyscript","blockchain-technology","typescript","web3"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/derkiner.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,"publiccode":null,"codemeta":null}},"created_at":"2022-04-16T08:29:51.000Z","updated_at":"2024-07-29T16:58:25.667Z","dependencies_parsed_at":"2023-04-17T21:17:05.690Z","dependency_job_id":null,"html_url":"https://github.com/derkiner/Near-Deploying-A-Sample-Contract-","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"Learn-NEAR/starter--near-sdk-as","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derkiner%2FNear-Deploying-A-Sample-Contract-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derkiner%2FNear-Deploying-A-Sample-Contract-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derkiner%2FNear-Deploying-A-Sample-Contract-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derkiner%2FNear-Deploying-A-Sample-Contract-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derkiner","download_url":"https://codeload.github.com/derkiner/Near-Deploying-A-Sample-Contract-/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242798263,"owners_count":20186882,"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":["assemblyscript","blockchain-technology","typescript","web3"],"created_at":"2024-07-29T16:55:00.781Z","updated_at":"2025-03-10T05:32:16.124Z","avatar_url":"https://github.com/derkiner.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `near-sdk-as` Starter Kit\n\nThis is a good project to use as a starting point for your AssemblyScript project.\n\n## Samples\n\nThis repository includes a complete project structure for AssemblyScript contracts targeting the NEAR platform.\n\nThe example here is very basic.  It's a simple contract demonstrating the following concepts:\n- a single contract\n- the difference between `view` vs. `change` methods\n- basic contract storage\n\nThere are 2 AssemblyScript contracts in this project, each in their own folder:\n\n- **simple** in the `src/simple` folder\n- **singleton** in the `src/singleton` folder\n\n### Simple\n\nWe say that an AssemblyScript contract is written in the \"simple style\" when the `index.ts` file (the contract entry point) includes a series of exported functions.\n\nIn this case, all exported functions become public contract methods.\n\n```ts\n// return the string 'hello world'\nexport function helloWorld(): string {}\n\n// read the given key from account (contract) storage\nexport function read(key: string): string {}\n\n// write the given value at the given key to account (contract) storage\nexport function write(key: string, value: string): string {}\n\n// private helper method used by read() and write() above\nprivate storageReport(): string {}\n```\n\n### Singleton\n\nWe say that an AssemblyScript contract is written in the \"singleton style\" when the `index.ts` file (the contract entry point) has a single exported class (the name of the class doesn't matter) that is decorated with `@nearBindgen`.\n\nIn this case, all methods on the class become public contract methods unless marked `private`.  Also, all instance variables are stored as a serialized instance of the class under a special storage key named `STATE`.  AssemblyScript uses JSON for storage serialization (as opposed to Rust contracts which use a custom binary serialization format called borsh).\n\n```ts\n@nearBindgen\nexport class Contract {\n\n  // return the string 'hello world'\n  helloWorld(): string {}\n\n  // read the given key from account (contract) storage\n  read(key: string): string {}\n\n  // write the given value at the given key to account (contract) storage\n  @mutateState()\n  write(key: string, value: string): string {}\n\n  // private helper method used by read() and write() above\n  private storageReport(): string {}\n}\n```\n\n\n## Usage\n\n### Getting started\n\n(see below for video recordings of each of the following steps)\n\nINSTALL `NEAR CLI` first like this: `npm i -g near-cli`\n\n1. clone this repo to a local folder\n2. run `yarn`\n3. run `./scripts/1.dev-deploy.sh`\n3. run `./scripts/2.use-contract.sh`\n4. run `./scripts/2.use-contract.sh` (yes, run it to see changes)\n5. run `./scripts/3.cleanup.sh`\n\n### Videos\n\n**`1.dev-deploy.sh`**\n\nThis video shows the build and deployment of the contract.\n\n[![asciicast](https://asciinema.org/a/409575.svg)](https://asciinema.org/a/409575)\n\n**`2.use-contract.sh`**\n\nThis video shows contract methods being called.  You should run the script twice to see the effect it has on contract state.\n\n[![asciicast](https://asciinema.org/a/409577.svg)](https://asciinema.org/a/409577)\n\n**`3.cleanup.sh`**\n\nThis video shows the cleanup script running.  Make sure you add the `BENEFICIARY` environment variable. The script will remind you if you forget.\n\n```sh\nexport BENEFICIARY=\u003cyour-account-here\u003e   # this account receives contract account balance\n```\n\n[![asciicast](https://asciinema.org/a/409580.svg)](https://asciinema.org/a/409580)\n\n### Other documentation\n\n- See `./scripts/README.md` for documentation about the scripts\n- Watch this video where Willem Wyndham walks us through refactoring a simple example of a NEAR smart contract written in AssemblyScript\n\n  https://youtu.be/QP7aveSqRPo\n\n  ```\n  There are 2 \"styles\" of implementing AssemblyScript NEAR contracts:\n  - the contract interface can either be a collection of exported functions\n  - or the contract interface can be the methods of a an exported class\n\n  We call the second style \"Singleton\" because there is only one instance of the class which is serialized to the blockchain storage.  Rust contracts written for NEAR do this by default with the contract struct.\n\n   0:00 noise (to cut)\n   0:10 Welcome\n   0:59 Create project starting with \"npm init\"\n   2:20 Customize the project for AssemblyScript development\n   9:25 Import the Counter example and get unit tests passing\n  18:30 Adapt the Counter example to a Singleton style contract\n  21:49 Refactoring unit tests to access the new methods\n  24:45 Review and summary\n  ```\n\n## The file system\n\n```sh\n├── README.md                          # this file\n├── as-pect.config.js                  # configuration for as-pect (AssemblyScript unit testing)\n├── asconfig.json                      # configuration for AssemblyScript compiler (supports multiple contracts)\n├── package.json                       # NodeJS project manifest\n├── scripts\n│   ├── 1.dev-deploy.sh                # helper: build and deploy contracts\n│   ├── 2.use-contract.sh              # helper: call methods on ContractPromise\n│   ├── 3.cleanup.sh                   # helper: delete build and deploy artifacts\n│   └── README.md                      # documentation for helper scripts\n├── src\n│   ├── as_types.d.ts                  # AssemblyScript headers for type hints\n│   ├── simple                         # Contract 1: \"Simple example\"\n│   │   ├── __tests__\n│   │   │   ├── as-pect.d.ts           # as-pect unit testing headers for type hints\n│   │   │   └── index.unit.spec.ts     # unit tests for contract 1\n│   │   ├── asconfig.json              # configuration for AssemblyScript compiler (one per contract)\n│   │   └── assembly\n│   │       └── index.ts               # contract code for contract 1\n│   ├── singleton                      # Contract 2: \"Singleton-style example\"\n│   │   ├── __tests__\n│   │   │   ├── as-pect.d.ts           # as-pect unit testing headers for type hints\n│   │   │   └── index.unit.spec.ts     # unit tests for contract 2\n│   │   ├── asconfig.json              # configuration for AssemblyScript compiler (one per contract)\n│   │   └── assembly\n│   │       └── index.ts               # contract code for contract 2\n│   ├── tsconfig.json                  # Typescript configuration\n│   └── utils.ts                       # common contract utility functions\n└── yarn.lock                          # project manifest version lock\n```\n\nYou may clone this repo to get started OR create everything from scratch.\n\nPlease note that, in order to create the AssemblyScript and tests folder structure, you may use the command `asp --init` which will create the following folders and files:\n\n```\n./assembly/\n./assembly/tests/\n./assembly/tests/example.spec.ts\n./assembly/tests/as-pect.d.ts\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderkiner%2FNear-Deploying-A-Sample-Contract-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderkiner%2FNear-Deploying-A-Sample-Contract-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderkiner%2FNear-Deploying-A-Sample-Contract-/lists"}