From b34ce57b0cd772db11ffe31aee4af00885696f4e Mon Sep 17 00:00:00 2001 From: Owen <124691791+PiVortex@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:19:40 +0700 Subject: [PATCH] update anatomy auction snippets+ fix auction commands (#2254) * fix auction commands * update anatomy auction snippets --------- Co-authored-by: PiVortex --- .../2.smart-contracts/anatomy/functions.md | 40 +++++++++---------- .../2.smart-contracts/anatomy/storage.md | 18 ++++----- .../2.smart-contracts/anatomy/types.md | 16 ++++---- docs/3.tutorials/auction/1.3-deploy.md | 16 ++++---- docs/3.tutorials/auction/4-factory.md | 10 ++--- 5 files changed, 49 insertions(+), 51 deletions(-) diff --git a/docs/2.build/2.smart-contracts/anatomy/functions.md b/docs/2.build/2.smart-contracts/anatomy/functions.md index 9d4327aaf79..60fd134ad7c 100644 --- a/docs/2.build/2.smart-contracts/anatomy/functions.md +++ b/docs/2.build/2.smart-contracts/anatomy/functions.md @@ -14,7 +14,7 @@ Smart contracts expose functions so users can interact with them. There are diff - + ### Contract's Interface @@ -45,49 +45,49 @@ impl MyTrait for MyContractStructure { - + ### Initialization Functions A contract can opt to have an initialization function. If present, this function must be called before any other to [initialize the contract](./storage.md). - + #### `@initialize({ privateFunction: true })` The initialization function is marked with the `@initialize` decorator. - + #### `#[init]` -Read-only functions are those that take an **immutable** reference to `self` in Rust. +The initialization function is marked with the `#[init]` macro. - + ### State Changing Functions The functions that modify the [state](./storage.md) or perform [actions](./actions.md) need to be called by a user with a NEAR account, since a transaction is required to execute them. - + #### `@call` State changing functions are marked with the `@call` decorator. - + #### `mut &self` State changing functions are those that take a **mutable** reference to `self` in Rust. - + :::tip @@ -97,28 +97,28 @@ The SDK provides [contextual information](./environment.md), such as which accou - + ### Read-Only Functions Contract's functions can be read-only, meaning they don't modify the state. Calling them is free for everyone, and does not require to have a NEAR account. - + #### `@view` Read-only functions are marked with the `@view` decorator in TS/JS. - + #### `&self` Read-only functions are those that take an **immutable** reference to `self` in Rust. - + ### Private Functions Many times you will want to have functions that **are exposed** as part of the contract's interface, but **should not be called directly** by users. @@ -129,21 +129,21 @@ These functions are marked as `private` in the contract's code, and can only be - + #### `decorator({privateFunction: true})` Private functions are marked by setting `privateFunction: true` in the `@call` or `@initialization` decorators. - + #### [#private] Private functions are marked using the `#[private]` macro in Rust. - + ### Payable Functions By default, functions will panic if the user attaches NEAR Tokens to the call. Functions that accept NEAR Tokens must be marked as `payable`. @@ -152,14 +152,14 @@ Within the function, the user will have access to the [attached deposit](./envir - + #### `@call({payableFunction: true})` Payable functions are marked by setting `payableFunction: true` in the `@call` decorator. - + #### [#payable] Payable functions are marked using the `#[payable]` macro in Rust. @@ -224,9 +224,9 @@ They are useful to return hardcoded values on the contract. - + - + diff --git a/docs/2.build/2.smart-contracts/anatomy/storage.md b/docs/2.build/2.smart-contracts/anatomy/storage.md index e122f8eb442..3711ec87f64 100644 --- a/docs/2.build/2.smart-contracts/anatomy/storage.md +++ b/docs/2.build/2.smart-contracts/anatomy/storage.md @@ -17,7 +17,7 @@ It is important to know that the account's **code** and account's **storage** ar - + ### Defining the State The attributes of the `class` marked as the contract define the data that will be stored. @@ -30,7 +30,7 @@ It is important to know that the account's **code** and account's **storage** ar - + ### Defining the State The attributes of the `struct` marked as the contract define the data that will be stored. @@ -69,7 +69,7 @@ It currently costs ~**1Ⓝ** to store **100KB** of data. - + ### I. Initialization Functions An option to initialize the state is to create an `initialization` function, which needs to be called before executing any other function. @@ -80,7 +80,7 @@ It currently costs ~**1Ⓝ** to store **100KB** of data. - + :::warning @@ -90,7 +90,7 @@ In TS/JS you still **must** set default values for the attributes, so the SDK ca - + ### I. Initialization Functions An option to initialize the state is to create an `initialization` function, which needs to be called before executing any other function. @@ -153,16 +153,16 @@ Make sure to read the [updating a contract](../release/upgrade.md) if you run in + url="https://github.com/near-examples/auctions-tutorial/blob/main/contract-ts/01-basic-auction/src/contract.ts" + start="2" end="60" /> + url="https://github.com/near-examples/auctions-tutorial/blob/main/contract-rs/01-basic-auction/src/lib.rs" + start="2" end="83" /> - + :::warning `U64/U128` @@ -71,7 +71,7 @@ To simplify development, the SDK provides the `U64` and `U128` types which are a - + ### Handling Tokens `$NEAR` tokens are typed as `BigInt` in JS, and their values represented in `yoctonear` @@ -80,7 +80,7 @@ To simplify development, the SDK provides the `U64` and `U128` types which are a - + ### Handling Tokens `$NEAR` tokens are handled through the `NearToken` struct, which exposes methods to represent the value in `yoctonear`, `milinear` and `near` @@ -89,7 +89,7 @@ To simplify development, the SDK provides the `U64` and `U128` types which are a - + ### Account The SDK exposes a special type to handle NEAR Accounts, which automatically checks if the account address is valid @@ -105,11 +105,11 @@ To simplify development, the SDK provides the `U64` and `U128` types which are a start="2" end="32" /> + url="https://github.com/near-examples/auctions-tutorial/blob/main/contract-ts/01-basic-auction/src/contract.ts" + start="2" end="61" /> + url="https://github.com/near-examples/auctions-tutorial/blob/main/contract-rs/01-basic-auction/src/lib.rs" + start="2" end="84" /> diff --git a/docs/3.tutorials/auction/1.3-deploy.md b/docs/3.tutorials/auction/1.3-deploy.md index 89eebfe9d66..5bac133dbae 100644 --- a/docs/3.tutorials/auction/1.3-deploy.md +++ b/docs/3.tutorials/auction/1.3-deploy.md @@ -55,15 +55,13 @@ To deploy the contract, you need to compile the contract code into WebAssembly ( npm run build # deploy the contract - near deploy ./build/auction.wasm + near deploy ./build/auction-contract.wasm # initialize the contract, it finishes in 2 minutes - MINUTE_FROM_NOW=$(date -v+2M +%s000000000) - near call init '{"end_time": "'$MINUTE_FROM_NOW'", "auctioneer": ""}' --accountId + TWO_MINUTES_FROM_NOW=$(date -v+2M +%s000000000) + near call init '{"end_time": "'$TWO_MINUTES_FROM_NOW'", "auctioneer": ""}' --accountId ``` - Replace `` with the name of another account, this should not be the same as the contract account as we intend on removing its keys. - @@ -73,17 +71,19 @@ To deploy the contract, you need to compile the contract code into WebAssembly ( cargo near build # deploy the contract - near deploy ./target/near/contract_rs.wasm + near deploy ./target/near/auction-contract.wasm # initialize the contract, it finishes in 2 minutes - MINUTE_FROM_NOW=$(date -v+2M +%s000000000) - near call init '{"end_time": "'$MINUTE_FROM_NOW'"}' --accountId + TWO_MINUTES_FROM_NOW=$(date -v+2M +%s000000000) + near call init '{"end_time": "'$TWO_MINUTES_FROM_NOW'", "auctioneer": ""}' --accountId ``` +Replace `` with the name of another account, this should not be the same as the contract account as we intend on removing its keys. + --- ## Locking the contract diff --git a/docs/3.tutorials/auction/4-factory.md b/docs/3.tutorials/auction/4-factory.md index f1915126828..003c58a7060 100644 --- a/docs/3.tutorials/auction/4-factory.md +++ b/docs/3.tutorials/auction/4-factory.md @@ -60,19 +60,17 @@ In this fork, we have also removed the option to add an access key to the contra Build and deploy the factory like you would any other contract, this time without any initialization parameters. ```bash +# compile the contract using cargo-near cargo near build -``` - -then -```bash -cargo near deploy without-init-call network-config testnet sign-with-legacy-keychain send +# deploy the contract +near deploy ./target/near/contract.wasm ``` You can now use the factory to deploy new auction contracts, here is an example command. ```bash -near call auction-factory.testnet deploy_new_auction '{"name": "new-auction", "end_time": "3000000000000000000", "auctioneer": "pivortex.testnet", "ft_contract": "dai.fakes.testnet", "nft_contract": "nft.examples.testnet", "token_id": "7777", "starting_price": "1000000000000000000"}' --accountId --deposit '1.6 NEAR' +near call auction-factory.testnet deploy_new_auction '{"name": "new-auction", "end_time": "3000000000000000000", "auctioneer": "pivortex.testnet", "ft_contract": "dai.fakes.testnet", "nft_contract": "nft.examples.testnet", "token_id": "7777", "starting_price": "1000000000000000000"}' --accountId pivortex.testnet --deposit 1.6 --gas 100000000000000 ``` :::info Deposit and storage costs