-
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.
- Loading branch information
PiVortex
committed
Oct 14, 2024
1 parent
d97e3fc
commit 2400c6b
Showing
10 changed files
with
199 additions
and
318 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
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 shows you 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.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) part 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.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.