Buy and sell movie posters and store information on near blockchain.
This repository includes a complete project structure for AssemblyScript contracts targeting the NEAR platform.
The example here is very basic. It's a simple contract demonstrating the following concepts:
- a single contract
- the difference between
viewvs.changemethods
// [view method] return information about the project
public getProjectInfo(): string {}
// [view method] returns an array of posters owned by an account
public fetchMovieListByAccountId(accountId: AccountId): MoviePoster[] {}
// [change method] returns a poster bought by context.sender
@mutateState()
public buyMoviePoster(item: Item): MoviePoster {}
// [change method] called to sell a poster bought by context.sender
@mutateState()
public sellMoviePoster(ft: MoviePoster): void {}(see below for video recordings of each of the following steps)
INSTALL NEAR CLI first like this: npm i -g near-cli
-
open git bash
-
run
npm installfrom project directory and frontend directory -
run
near loginfrom project directory -
run
npm run devfrom project directory -
Modify the line in
frontend/src/lib/config.jsthat sets the account name of the contract.Set it to the account id you got from previous step.
CONTRACT_NAME=dev-xxxxxxxxxxxx-xxxxxxxxxxxxxx -
Modify the line in
assembly/__tests__/index.spec.tsthat sets the accountId.Set it to the account id of your testnet account.
accountId=process.env.CONTRACT_NAME || "your-account-id.testnet" -
run
npm run testfrom project directory -
run
npm startfrom frontend directory
1. Install required packages using npm package manager
This video shows the installation of required packages using npm package manager.
2. Build and deploy smart contract
This video shows the build and deployment of the contract.
3. App demo
This video shows contract methods being called from the react frontend.
Each account on NEAR can have at most one contract deployed to it. If you've already created an account such as your-name.testnet, you can deploy your contract to near-market.your-name.testnet. Assuming you've already created an account on [NEAR Wallet], here's how to create near-market.your-name.testnet:
-
Authorize NEAR CLI, following the commands it gives you:
near login
-
Create a subaccount (replace
YOUR-NAMEbelow with your actual account name):near create-account near-market.YOUR-NAME.testnet --masterAccount YOUR-NAME.testnet