-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from near-examples/update-readmes
Update readmes
- Loading branch information
Showing
10 changed files
with
197 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
# Auction Examples 🧑⚖️ | ||
# Auctions Tutorial 🧑⚖️ | ||
[![](https://img.shields.io/badge/⋈%20Examples-Basics-green)](https://docs.near.org/tutorials/welcome) | ||
[![](https://img.shields.io/badge/Contract-JS-yellow)](contract-ts) | ||
[![](https://img.shields.io/badge/Contract-Rust-red)](contract-rs) | ||
![example workflow](https://github.com/near-examples/auction-examples/actions/workflows/tests-ts.yml/badge.svg) | ||
![example workflow](https://github.com/near-examples/auction-examples/actions/workflows/tests-rs.yml/badge.svg) | ||
|
||
This repository contains examples of a simple Auction smart contract in both JavaScript and Rust. | ||
This repository contains examples that are used as part of the [Auction Tutorial](https://docs.near.org/vi/tutorials/auction/basic-auction) in the documentation. | ||
|
||
- [JavaScript Contract](contract-ts) | ||
- [Rust Contract](contract-ts) | ||
The repo contains three versions of an auction contract written in both Rust and JavaScript. The first contract is a simple auction where you can place bids and claim the auction, the second introduces NFTs as a prize and the final contract uses fungible tokens to place bids. | ||
- [JavaScript Contracts](./contract-ts) | ||
- [Rust Contracts](./contract-rs) | ||
|
||
<br /> | ||
This repo also has two different frontends, one for the simple auction and one for the final contract that uses FTs and NFTs. | ||
- [Frontends](./frontends/) | ||
|
||
# What These Examples Show | ||
Lastly, this repo contains a factory contract written in rust that is used to deploy new auctions and initialize them. | ||
- [Factory Contract](./factory) | ||
|
||
1. How to store and retrieve information in the NEAR network. | ||
--- | ||
|
||
<br /> | ||
## What These Examples Show | ||
|
||
- [Creating a simple smart contract](https://docs.near.org/tutorials/auction/basic-auction#the-contracts-state) | ||
- [Writing tests for a contract](https://docs.near.org/tutorials/auction/sandbox-testing) | ||
- [Deploying a contract to testnet](https://docs.near.org/tutorials/auction/deploy) | ||
- [Locking a contract](https://docs.near.org/tutorials/auction/deploy#locking-the-contract) | ||
- [Creating a frontend to interact with the contract](https://docs.near.org/tutorials/auction/creating-a-frontend) | ||
- [Using an indexing API to view historical bids](https://docs.near.org/tutorials/auction/indexing-historical-data) | ||
- [Making cross-contract calls](https://docs.near.org/tutorials/auction/winning-an-nft#transferring-the-nft-to-the-winner) | ||
- [Using Non-Fungible Tokens](https://docs.near.org/tutorials/auction/winning-an-nft) | ||
- [Using Fungible Tokens](https://docs.near.org/tutorials/auction/bidding-with-fts) | ||
- [Modifying a factory contract to deploy your own contracts](https://docs.near.org/tutorials/auction/auction-factory) | ||
|
||
# Learn More | ||
1. Learn more about the contract through its [README](./contract-ts/README.md). | ||
2. Check [**our documentation**](https://docs.near.org/build/welcome). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,47 @@ | ||
# Hello NEAR Contract | ||
|
||
The smart contract exposes two methods to enable storing and retrieving a greeting in the NEAR network. | ||
|
||
```ts | ||
@NearBindgen({}) | ||
class HelloNear { | ||
greeting: string = "Hello"; | ||
|
||
@view // This method is read-only and can be called for free | ||
get_greeting(): string { | ||
return this.greeting; | ||
} | ||
|
||
@call // This method changes the state, for which it cost gas | ||
set_greeting({ greeting }: { greeting: string }): void { | ||
// Record a log permanently to the blockchain! | ||
near.log(`Saving greeting ${greeting}`); | ||
this.greeting = greeting; | ||
} | ||
} | ||
``` | ||
|
||
<br /> | ||
# Basic Auction Contract | ||
|
||
# Quickstart | ||
This directory contains a JavaScript contract that is used as part of the [Basic Auction Tutorial](https://docs.near.org/tutorials/auction/basic-auction). | ||
|
||
1. Make sure you have installed [node.js](https://nodejs.org/en/download/package-manager/) >= 16. | ||
2. Install the [`NEAR CLI`](https://github.com/near/near-cli#setup) | ||
The contract is a simple auction where you can place bids, view the highest bid, and claim the tokens at the end of the auction. | ||
|
||
<br /> | ||
This repo showcases the basic anatomy of a contract including how to store data in a contract, how to update the state, and then how to view it. It also looks at how to use environment variables and macros. We have also written sandbox test the contract locally. | ||
|
||
## 1. Build and Test the Contract | ||
You can automatically compile and test the contract by running: | ||
--- | ||
|
||
```bash | ||
npm run build | ||
``` | ||
## How to Build Locally? | ||
|
||
<br /> | ||
Install the [NEAR CLI](https://docs.near.org/tools/near-cli#installation) and run: | ||
|
||
## 2. Create an Account and Deploy the Contract | ||
You can create a new account and deploy the contract by running: | ||
Install the dependencies: | ||
|
||
```bash | ||
near create-account <your-account.testnet> --useFaucet | ||
near deploy <your-account.testnet> build/release/hello_near.wasm | ||
npm install | ||
``` | ||
|
||
<br /> | ||
|
||
|
||
## 3. Retrieve the Greeting | ||
|
||
`get_greeting` is a read-only method (aka `view` method). | ||
|
||
`View` methods can be called for **free** by anyone, even people **without a NEAR account**! | ||
Build the contract: | ||
|
||
```bash | ||
# Use near-cli to get the greeting | ||
near view <your-account.testnet> get_greeting | ||
npm run build | ||
``` | ||
|
||
<br /> | ||
|
||
## 4. Store a New Greeting | ||
`set_greeting` changes the contract's state, for which it is a `call` method. | ||
|
||
`Call` methods can only be invoked using a NEAR account, since the account needs to pay GAS for the transaction. | ||
## How to Test Locally? | ||
|
||
```bash | ||
# Use near-cli to set a new greeting | ||
near call <your-account.testnet> set_greeting '{"greeting":"howdy"}' --accountId <your-account.testnet> | ||
npm run test | ||
``` | ||
|
||
**Tip:** If you would like to call `set_greeting` using another account, first login into NEAR using: | ||
## How to Deploy? | ||
|
||
Install the [NEAR CLI](https://docs.near.org/tools/near-cli#installation) and run: | ||
|
||
```bash | ||
# Use near-cli to login your NEAR account | ||
near login | ||
``` | ||
# Create a new account | ||
near create <contractId> --useFaucet | ||
|
||
# Deploy the contract | ||
near deploy <contractId> ./build/auction-contract.wasm | ||
|
||
and then use the logged account to sign the transaction: `--accountId <another-account>`. | ||
# Initialize the contract | ||
TWO_MINUTES_FROM_NOW=$(date -v+2M +%s000000000) | ||
near call <contractId> init '{"end_time": "'$TWO_MINUTES_FROM_NOW'", "auctioneer": "<auctioneerAccountId>"}' --accountId <contractId> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,45 @@ | ||
# Hello NEAR Contract | ||
|
||
The smart contract exposes two methods to enable storing and retrieving a greeting in the NEAR network. | ||
|
||
```ts | ||
@NearBindgen({}) | ||
class HelloNear { | ||
greeting: string = "Hello"; | ||
|
||
@view // This method is read-only and can be called for free | ||
get_greeting(): string { | ||
return this.greeting; | ||
} | ||
|
||
@call // This method changes the state, for which it cost gas | ||
set_greeting({ greeting }: { greeting: string }): void { | ||
// Record a log permanently to the blockchain! | ||
near.log(`Saving greeting ${greeting}`); | ||
this.greeting = greeting; | ||
} | ||
} | ||
``` | ||
# NFT Auction Contract | ||
|
||
This directory contains a JavaScript contract that is used as part of the [Winning an NFT](https://docs.near.org/tutorials/auction/winning-an-nft) section of the auction tutorial. | ||
|
||
<br /> | ||
In this part the contract is adapted so the auction is initialized with an NFT and the winner of the auction is sent the NFT. It is a great way to learn how to work with NFTs in NEAR. | ||
|
||
# Quickstart | ||
--- | ||
|
||
1. Make sure you have installed [node.js](https://nodejs.org/en/download/package-manager/) >= 16. | ||
2. Install the [`NEAR CLI`](https://github.com/near/near-cli#setup) | ||
## How to Build Locally? | ||
|
||
<br /> | ||
Install the [NEAR CLI](https://docs.near.org/tools/near-cli#installation) and run: | ||
|
||
## 1. Build and Test the Contract | ||
You can automatically compile and test the contract by running: | ||
Install the dependencies: | ||
|
||
```bash | ||
npm run build | ||
npm install | ||
``` | ||
|
||
<br /> | ||
|
||
## 2. Create an Account and Deploy the Contract | ||
You can create a new account and deploy the contract by running: | ||
Build the contract: | ||
|
||
```bash | ||
near create-account <your-account.testnet> --useFaucet | ||
near deploy <your-account.testnet> build/release/hello_near.wasm | ||
npm run build | ||
``` | ||
|
||
<br /> | ||
|
||
|
||
## 3. Retrieve the Greeting | ||
|
||
`get_greeting` is a read-only method (aka `view` method). | ||
|
||
`View` methods can be called for **free** by anyone, even people **without a NEAR account**! | ||
## How to Test Locally? | ||
|
||
```bash | ||
# Use near-cli to get the greeting | ||
near view <your-account.testnet> get_greeting | ||
npm run test | ||
``` | ||
|
||
<br /> | ||
## How to Deploy? | ||
|
||
## 4. Store a New Greeting | ||
`set_greeting` changes the contract's state, for which it is a `call` method. | ||
|
||
`Call` methods can only be invoked using a NEAR account, since the account needs to pay GAS for the transaction. | ||
Install the [NEAR CLI](https://docs.near.org/tools/near-cli#installation) and run: | ||
|
||
```bash | ||
# Use near-cli to set a new greeting | ||
near call <your-account.testnet> set_greeting '{"greeting":"howdy"}' --accountId <your-account.testnet> | ||
``` | ||
# Create a new account | ||
near create <contractId> --useFaucet | ||
|
||
**Tip:** If you would like to call `set_greeting` using another account, first login into NEAR using: | ||
|
||
```bash | ||
# Use near-cli to login your NEAR account | ||
near login | ||
``` | ||
# Deploy the contract | ||
near deploy <contractId> ./build/auction-contract.wasm | ||
|
||
and then use the logged account to sign the transaction: `--accountId <another-account>`. | ||
# Initialize the contract | ||
TWO_MINUTES_FROM_NOW=$(date -v+2M +%s000000000) | ||
near call <contractId> init '{"end_time": "'$TWO_MINUTES_FROM_NOW'", "auctioneer": "<auctioneerAccountId>", "nft_contract": "<nftContractId>", "token_id": "<tokenId>"}' --accountId <contractId> | ||
``` |
Oops, something went wrong.