Skip to content

Commit

Permalink
Merge pull request #17 from near-examples/update-readmes
Browse files Browse the repository at this point in the history
Update readmes
  • Loading branch information
PiVortex authored Oct 15, 2024
2 parents d97e3fc + 4b9ea5e commit 657068f
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 319 deletions.
35 changes: 22 additions & 13 deletions README.md
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).
30 changes: 15 additions & 15 deletions contract-rs/01-basic-auction/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# contract-rs
# Basic Auction Contract

cargo-near-new-project-description
This directory contains a Rust contract that is used as part of the [Basic Auction Tutorial](https://docs.near.org/tutorials/auction/basic-auction).

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.

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.

---

## How to Build Locally?

Expand All @@ -18,22 +24,16 @@ cargo test

## How to Deploy?

To deploy manually, install [`cargo-near`](https://github.com/near/cargo-near) and run:
To deploy manually, install [NEAR CLI](https://docs.near.org/tools/near-cli#installation) and run:

```bash
# Create a new account
cargo near create-dev-account
near create <contractId> --useFaucet

# Deploy the contract on it
cargo near deploy <account-id>
near deploy <contractId> ./target/near/auction-contract.wasm

# 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>
```
## Useful Links

- [cargo-near](https://github.com/near/cargo-near) - NEAR smart contract development toolkit for Rust
- [near CLI](https://near.cli.rs) - Iteract with NEAR blockchain from command line
- [NEAR Rust SDK Documentation](https://docs.near.org/sdk/rust/introduction)
- [NEAR Documentation](https://docs.near.org)
- [NEAR StackOverflow](https://stackoverflow.com/questions/tagged/nearprotocol)
- [NEAR Discord](https://near.chat)
- [NEAR Telegram Developers Community Group](https://t.me/neardev)
- NEAR DevHub: [Telegram](https://t.me/neardevhub), [Twitter](https://twitter.com/neardevhub)
28 changes: 12 additions & 16 deletions contract-rs/02-winner-gets-nft/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# contract-rs
# NFT Auction contract

cargo-near-new-project-description
This directory contains a Rust 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.

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.

## How to Build Locally?

Expand All @@ -18,22 +20,16 @@ cargo test

## How to Deploy?

To deploy manually, install [`cargo-near`](https://github.com/near/cargo-near) and run:
To deploy manually, install [NEAR CLI](https://docs.near.org/tools/near-cli#installation) and run:

```bash
# Create a new account
cargo near create-dev-account
near create <contractId> --useFaucet

# Deploy the contract on it
cargo near deploy <account-id>
```
## Useful Links

- [cargo-near](https://github.com/near/cargo-near) - NEAR smart contract development toolkit for Rust
- [near CLI](https://near.cli.rs) - Iteract with NEAR blockchain from command line
- [NEAR Rust SDK Documentation](https://docs.near.org/sdk/rust/introduction)
- [NEAR Documentation](https://docs.near.org)
- [NEAR StackOverflow](https://stackoverflow.com/questions/tagged/nearprotocol)
- [NEAR Discord](https://near.chat)
- [NEAR Telegram Developers Community Group](https://t.me/neardev)
- NEAR DevHub: [Telegram](https://t.me/neardevhub), [Twitter](https://twitter.com/neardevhub)
near deploy <contractId> ./target/near/auction-contract.wasm

# 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>
```
28 changes: 12 additions & 16 deletions contract-rs/03-bid-with-fts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# contract-rs
# Auction contract with FTs

cargo-near-new-project-description
This directory contains a Rust contract that is used as part of the [Bidding with FTs](https://docs.near.org/tutorials/auction/bidding-with-fts) section of the auction tutorial.

In this part the contract is adapted so users can bid in fungible tokens (FTs) instead of NEAR tokens. It is a great way to learn how to work with FTs in NEAR.

## How to Build Locally?

Expand All @@ -18,22 +20,16 @@ cargo test

## How to Deploy?

To deploy manually, install [`cargo-near`](https://github.com/near/cargo-near) and run:
To deploy manually, install [NEAR CLI](https://docs.near.org/tools/near-cli#installation) and run:

```bash
# Create a new account
cargo near create-dev-account
near create <contractId> --useFaucet

# Deploy the contract on it
cargo near deploy <account-id>
```
## Useful Links

- [cargo-near](https://github.com/near/cargo-near) - NEAR smart contract development toolkit for Rust
- [near CLI](https://near.cli.rs) - Iteract with NEAR blockchain from command line
- [NEAR Rust SDK Documentation](https://docs.near.org/sdk/rust/introduction)
- [NEAR Documentation](https://docs.near.org)
- [NEAR StackOverflow](https://stackoverflow.com/questions/tagged/nearprotocol)
- [NEAR Discord](https://near.chat)
- [NEAR Telegram Developers Community Group](https://t.me/neardev)
- NEAR DevHub: [Telegram](https://t.me/neardevhub), [Twitter](https://twitter.com/neardevhub)
near deploy <contractId> ./target/near/auction-contract.wasm

# Initialize the contract
TWO_MINUTES_FROM_NOW=$(date -v+2M +%s000000000)
near call <contractId> init '{"end_time": "'$TWO_MINUTES_FROM_NOW'", "auctioneer": "<auctioneerAccountId>", "ft_contract": "<ftContractId>", "nft_contract": "<nftContractId>", "token_id": "<tokenId>", "starting_price": "<startingPrice>"}' --accountId <contractId>
```
86 changes: 25 additions & 61 deletions contract-ts/01-basic-auction/README.md
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>
```
84 changes: 23 additions & 61 deletions contract-ts/02-winner-gets-nft/README.md
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>
```
Loading

0 comments on commit 657068f

Please sign in to comment.