From c804b741868c80ea39ccdd30fd6bad1dec4824da Mon Sep 17 00:00:00 2001 From: garikbesson Date: Tue, 24 Dec 2024 20:11:54 +0100 Subject: [PATCH 1/7] init near-drop section --- docs/3.tutorials/examples/near-drop.md | 160 +++++++++++++++++++++++++ website/sidebars.js | 1 + 2 files changed, 161 insertions(+) create mode 100644 docs/3.tutorials/examples/near-drop.md diff --git a/docs/3.tutorials/examples/near-drop.md b/docs/3.tutorials/examples/near-drop.md new file mode 100644 index 0000000000..07fab29047 --- /dev/null +++ b/docs/3.tutorials/examples/near-drop.md @@ -0,0 +1,160 @@ +--- +id: near-drop +title: Near Drop +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import {CodeTabs, Language, Github} from "@site/src/components/codetabs" + +A near-drop is a smart contract that allows users to create NEAR/FT/NFT drop and claim created drops by another user using a PublicKey. + +We have two factory examples: + +1. [**Token Factory**](https://github.com/near-examples/token-factory): A factory that creates [fungible tokens](../fts/0-intro.md) contracts. +2. [**A Generic Factory**](https://github.com/near-examples/factory-rust): A factory that creates [donation contracts](./donation.md), but allows to change the contract it deploys. + +:::info +In this page we will focus on the Donation factory, to learn more about the token factory visit its repository. +::: + +--- + +## Generic Factory + +The [Generic Factory](https://github.com/near-examples/factory-rust/) presents a contract factory that: + +1. Creates sub-accounts of itself and deploys its contract on them (`create_factory_subaccount_and_deploy`). +2. Can change the stored contract using the `update_stored_contract` method. + + + + + + + + +--- + +## Quickstart + +1. Make sure you have installed [rust](https://www.rust-lang.org/). +2. Install the [`NEAR CLI`](/tools/near-cli#installation) + +
+ +### Build and Deploy the Factory + +You can automatically compile and deploy the contract in the NEAR testnet by running: + +```bash +./deploy.sh +``` + +Once finished, check the `neardev/dev-account` file to find the address in which the contract was deployed: + +```bash +cat ./neardev/dev-account +# e.g. dev-1659899566943-21539992274727 +``` + +
+ +### Deploy the Stored Contract Into a Sub-Account + +`create_factory_subaccount_and_deploy` will create a sub-account of the factory and deploy the +stored contract on it. + +```bash +near call create_factory_subaccount_and_deploy '{ "name": "sub", "beneficiary": ""}' --deposit 1.24 --accountId --gas 300000000000000 +``` + +This will create the `sub.`, which will have a `donation` contract deployed on it: + +```bash +near view sub. get_beneficiary +# expected response is: +``` + +
+ +### Update the Stored Contract + +`update_stored_contract` enables to change the compiled contract that the factory stores. + +The method is interesting because it has no declared parameters, and yet it takes +an input: the new contract to store as a stream of bytes. + +To use it, we need to transform the contract we want to store into its `base64` +representation, and pass the result as input to the method: + +```bash +# Use near-cli to update stored contract +export BYTES=`cat ./src/to/new-contract/contract.wasm | base64` +near call update_stored_contract "$BYTES" --base64 --accountId --gas 30000000000000 +``` + +> This works because the arguments of a call can be either a `JSON` object or a `String Buffer` + +--- + +## Factories - Concepts & Limitations + +Factories are an interesting concept, here we further explain some of their implementation aspects, +as well as their limitations. + +
+ +### Automatically Creating Accounts + +NEAR accounts can only create sub-accounts of itself, therefore, the `factory` can only create and +deploy contracts on its own sub-accounts. + +This means that the factory: + +1. **Can** create `sub.factory.testnet` and deploy a contract on it. +2. **Cannot** create sub-accounts of the `predecessor`. +3. **Can** create new accounts (e.g. `account.testnet`), but **cannot** deploy contracts on them. + +It is important to remember that, while `factory.testnet` can create `sub.factory.testnet`, it has +no control over it after its creation. + +
+ +### The Update Method + +The `update_stored_contracts` has a very short implementation: + +```rust +#[private] +pub fn update_stored_contract(&mut self) { + self.code = env::input().expect("Error: No input").to_vec(); +} +``` + +On first sight it looks like the method takes no input parameters, but we can see that its only +line of code reads from `env::input()`. What is happening here is that `update_stored_contract` +**bypasses** the step of **deserializing the input**. + +You could implement `update_stored_contract(&mut self, new_code: Vec)`, +which takes the compiled code to store as a `Vec`, but that would trigger the contract to: + +1. Deserialize the `new_code` variable from the input. +2. Sanitize it, making sure it is correctly built. + +When dealing with big streams of input data (as is the compiled `wasm` file to be stored), this process +of deserializing/checking the input ends up **consuming the whole GAS** for the transaction. + +:::note Versioning for this article + +At the time of this writing, this example works with the following versions: + +- near-cli: `4.0.13` +- node: `18.19.1` +- rustc: `1.77.0` + +::: diff --git a/website/sidebars.js b/website/sidebars.js index 5a3bf38132..923d61a40c 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -322,6 +322,7 @@ const sidebar = { { "Advanced Contracts": [ "tutorials/examples/factory", + "tutorials/examples/near-drop", "tutorials/examples/advanced-xcc", "tutorials/examples/update-contract-migrate-state", ] From 23e3c441d306c30ad6be69d2a071bb4b295f8839 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Thu, 26 Dec 2024 12:54:11 +0100 Subject: [PATCH 2/7] near-drop example first version --- docs/3.tutorials/examples/near-drop.md | 247 ++++++++++++++++--------- 1 file changed, 156 insertions(+), 91 deletions(-) diff --git a/docs/3.tutorials/examples/near-drop.md b/docs/3.tutorials/examples/near-drop.md index 07fab29047..4a1c7917e3 100644 --- a/docs/3.tutorials/examples/near-drop.md +++ b/docs/3.tutorials/examples/near-drop.md @@ -9,152 +9,217 @@ import {CodeTabs, Language, Github} from "@site/src/components/codetabs" A near-drop is a smart contract that allows users to create NEAR/FT/NFT drop and claim created drops by another user using a PublicKey. -We have two factory examples: +Particularly, it shows: -1. [**Token Factory**](https://github.com/near-examples/token-factory): A factory that creates [fungible tokens](../fts/0-intro.md) contracts. -2. [**A Generic Factory**](https://github.com/near-examples/factory-rust): A factory that creates [donation contracts](./donation.md), but allows to change the contract it deploys. +1. How to create a NEAR drop. +2. How to create a FT drop. +3. How to create a NFT drop. +4. How to claim a drop for an existing account. +5. How to claim a drop for a new account. -:::info -In this page we will focus on the Donation factory, to learn more about the token factory visit its repository. -::: +--- + +### Contract State + +- `top_level_account` - that account is used to create new accounts. It has to have `create_account` method. +- `drop_id_by_key` - that LookupMap structure contains relations between `PublicKey` and `DropId`. `PublicKey` is used to claim drop. `DropId` is a unique identificator by which you can get drop's data like amount of tokens to drop, FT or NFT contract, etc. +- `drop_by_id` - that LookupMap structure contains relations between `DropId` and actual drop data - `Drop`. + + --- -## Generic Factory +### Drop Types + +There are 3 types of drops, which differ in what the user will receive when he claims the corresponding drop - NEAR, fungible tokens (FTs) or non-fungible tokens (NFTs). + + + + + + + + + + +--- -The [Generic Factory](https://github.com/near-examples/factory-rust/) presents a contract factory that: +### Create a drop -1. Creates sub-accounts of itself and deploys its contract on them (`create_factory_subaccount_and_deploy`). -2. Can change the stored contract using the `update_stored_contract` method. +Creating drop functions looks very similar, the main difference is in the structures used to store the drop data. - - + + + --- -## Quickstart +### Claim a drop -1. Make sure you have installed [rust](https://www.rust-lang.org/). -2. Install the [`NEAR CLI`](/tools/near-cli#installation) +In order to claim drop claiming methods have to be called by near-drop contract and signed with a corresponding `PublicKey`. There are two ways to claim a drop: claim for an existing account and claim for a new account. In last case claimer account will be created. -
+When a drop is claimed, its `counter` decreases by 1 and corresponding relation between `PublicKey` and `DropId` removing from the contract state (`drop_id_by_key` collection). -### Build and Deploy the Factory +When all drops are claimed (`counter` == 0), relation between `DropId` and `Drop` removing from the `drop_by_id` collection as well. -You can automatically compile and deploy the contract in the NEAR testnet by running: +
-```bash -./deploy.sh -``` +#### Claim for an existing account -Once finished, check the `neardev/dev-account` file to find the address in which the contract was deployed: + + + + + + -```bash -cat ./neardev/dev-account -# e.g. dev-1659899566943-21539992274727 -``` +
-
+#### Claim for a new account -### Deploy the Stored Contract Into a Sub-Account + + + + + + + -`create_factory_subaccount_and_deploy` will create a sub-account of the factory and deploy the -stored contract on it. +--- -```bash -near call create_factory_subaccount_and_deploy '{ "name": "sub", "beneficiary": ""}' --deposit 1.24 --accountId --gas 300000000000000 -``` +### Testing the Contract -This will create the `sub.`, which will have a `donation` contract deployed on it: +The contract readily includes a sandbox testing to validate its functionality. To execute the tests, run the following command: -```bash -near view sub. get_beneficiary -# expected response is: -``` + + + + ```bash + cargo test + ``` -
+
+
-### Update the Stored Contract +:::tip +The `integration tests` use a sandbox to create NEAR users and simulate interactions with the contract. +::: -`update_stored_contract` enables to change the compiled contract that the factory stores. +--- -The method is interesting because it has no declared parameters, and yet it takes -an input: the new contract to store as a stream of bytes. +### Deploying the Contract to the NEAR network -To use it, we need to transform the contract we want to store into its `base64` -representation, and pass the result as input to the method: +In order to deploy the contract you will need to create a NEAR account. -```bash -# Use near-cli to update stored contract -export BYTES=`cat ./src/to/new-contract/contract.wasm | base64` -near call update_stored_contract "$BYTES" --base64 --accountId --gas 30000000000000 -``` + + -> This works because the arguments of a call can be either a `JSON` object or a `String Buffer` + ```bash + # Create a new account pre-funded by a faucet + near create-account --useFaucet + ``` + ---- + -## Factories - Concepts & Limitations + ```bash + # Create a new account pre-funded by a faucet + near account create-account sponsor-by-faucet-service .testnet autogenerate-new-keypair save-to-keychain network-config testnet create + ``` + + -Factories are an interesting concept, here we further explain some of their implementation aspects, -as well as their limitations. +Then build and deploy the contract: -
+```bash +cargo near build -### Automatically Creating Accounts +cargo near deploy with-init-call new json-args '{"top_level_account": "testnet"}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' network-config testnet sign-with-keychain send +``` -NEAR accounts can only create sub-accounts of itself, therefore, the `factory` can only create and -deploy contracts on its own sub-accounts. +--- -This means that the factory: +### CLI: Interacting with the Contract -1. **Can** create `sub.factory.testnet` and deploy a contract on it. -2. **Cannot** create sub-accounts of the `predecessor`. -3. **Can** create new accounts (e.g. `account.testnet`), but **cannot** deploy contracts on them. +To interact with the contract through the console, you can use the following commands: -It is important to remember that, while `factory.testnet` can create `sub.factory.testnet`, it has -no control over it after its creation. + + + + ```bash + # create a NEAR drop + near call create_near_drop '{"drop_id": "1", "public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' --accountId --deposit 1 --gas 300000000000000 -
+ # create a FT drop + near call create_ft_drop '{"drop_id": "1", "public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' --accountId --gas 300000000000000 -### The Update Method + # create a NFT drop + near call create_nft_drop '{"drop_id": "1", "public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' --accountId --gas 300000000000000 + + # claim to an existing account + near call claim_for '{"account_id": ""}' --accountId --privateKey -The `update_stored_contracts` has a very short implementation: + # claim to a new account + near call create_account_and_claim '{"account_id": ""}' --accountId --privateKey + ``` +
-```rust -#[private] -pub fn update_stored_contract(&mut self) { - self.code = env::input().expect("Error: No input").to_vec(); -} -``` + + + ```bash + # create a NEAR drop + near contract call-function as-transaction create_near_drop json-args '{"drop_id": "1", "public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' prepaid-gas '300.0 Tgas' attached-deposit '1 NEAR' sign-as network-config testnet sign-with-keychain send -On first sight it looks like the method takes no input parameters, but we can see that its only -line of code reads from `env::input()`. What is happening here is that `update_stored_contract` -**bypasses** the step of **deserializing the input**. + # create a FT drop + near contract call-function as-transaction create_ft_drop json-args '{"drop_id": "1", "public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send -You could implement `update_stored_contract(&mut self, new_code: Vec)`, -which takes the compiled code to store as a `Vec`, but that would trigger the contract to: + # create a NFT drop + near contract call-function as-transaction create_nft_drop json-args '{"drop_id": "1", "public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send -1. Deserialize the `new_code` variable from the input. -2. Sanitize it, making sure it is correctly built. + # claim to an existing account + near contract call-function as-transaction claim_for json-args '{"account_id": ""}' prepaid-gas '30.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-plaintext-private-key --signer-public-key ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q --signer-private-key ed25519:3yVFxYtyk7ZKEMshioC3BofK8zu2q6Y5hhMKHcV41p5QchFdQRzHYUugsoLtqV3Lj4zURGYnHqMqt7zhZZ2QhdgB send -When dealing with big streams of input data (as is the compiled `wasm` file to be stored), this process -of deserializing/checking the input ends up **consuming the whole GAS** for the transaction. + # claim to a new account + near contract call-function as-transaction create_account_and_claim json-args '{"account_id": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-plaintext-private-key --signer-public-key ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4 --signer-private-key ed25519:2xZcegrZvP52VrhehvApnx4McL85hcSBq1JETJrjuESC6v6TwTcr4VVdzxaCReyMCJvx9V4X1ppv8cFFeQZ6hJzU send + ``` + +
:::note Versioning for this article At the time of this writing, this example works with the following versions: -- near-cli: `4.0.13` -- node: `18.19.1` -- rustc: `1.77.0` +- near-cli: `0.17.0` +- rustc: `1.82.0` -::: +::: \ No newline at end of file From a5aee6406f69b8605d55cedb0d9d27c18b09fa51 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Fri, 3 Jan 2025 13:15:39 +0100 Subject: [PATCH 3/7] remove short version of claiming commands --- docs/3.tutorials/examples/near-drop.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/3.tutorials/examples/near-drop.md b/docs/3.tutorials/examples/near-drop.md index 4a1c7917e3..e0695488ca 100644 --- a/docs/3.tutorials/examples/near-drop.md +++ b/docs/3.tutorials/examples/near-drop.md @@ -187,10 +187,10 @@ To interact with the contract through the console, you can use the following com near call create_nft_drop '{"drop_id": "1", "public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' --accountId --gas 300000000000000 # claim to an existing account - near call claim_for '{"account_id": ""}' --accountId --privateKey + # see the full version # claim to a new account - near call create_account_and_claim '{"account_id": ""}' --accountId --privateKey + # see the full version ``` From d283b2f4750aa4495580884d39255f6e9da8bb77 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Tue, 7 Jan 2025 14:21:04 +0100 Subject: [PATCH 4/7] fix code lines --- docs/3.tutorials/examples/near-drop.md | 40 ++++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/3.tutorials/examples/near-drop.md b/docs/3.tutorials/examples/near-drop.md index e0695488ca..260cff00a2 100644 --- a/docs/3.tutorials/examples/near-drop.md +++ b/docs/3.tutorials/examples/near-drop.md @@ -11,23 +11,25 @@ A near-drop is a smart contract that allows users to create NEAR/FT/NFT drop and Particularly, it shows: -1. How to create a NEAR drop. -2. How to create a FT drop. -3. How to create a NFT drop. -4. How to claim a drop for an existing account. -5. How to claim a drop for a new account. +1. How to calculate storage costs +2. How to create a NEAR drop. +3. How to create a FT drop. +4. How to create a NFT drop. +5. How to claim a drop for an existing account. +6. How to claim a drop for a new account. --- ### Contract State - `top_level_account` - that account is used to create new accounts. It has to have `create_account` method. +- `next_drop_id` - that id will be assigned to the next created drop. - `drop_id_by_key` - that LookupMap structure contains relations between `PublicKey` and `DropId`. `PublicKey` is used to claim drop. `DropId` is a unique identificator by which you can get drop's data like amount of tokens to drop, FT or NFT contract, etc. - `drop_by_id` - that LookupMap structure contains relations between `DropId` and actual drop data - `Drop`. + start="26" end="31" /> --- @@ -62,13 +64,13 @@ Creating drop functions looks very similar, the main difference is in the struct + start="46" end="68" /> + start="70" end="91" /> + start="93" end="105" /> @@ -93,7 +95,7 @@ When all drops are claimed (`counter` == 0), relation between `DropId` and `Drop start="11" end="14" /> + start="58" end="85" /> @@ -105,13 +107,13 @@ When all drops are claimed (`counter` == 0), relation between `DropId` and `Drop + start="16" end="41" /> + start="43" end="56" /> + start="58" end="85" /> @@ -178,13 +180,13 @@ To interact with the contract through the console, you can use the following com ```bash # create a NEAR drop - near call create_near_drop '{"drop_id": "1", "public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' --accountId --deposit 1 --gas 300000000000000 + near call create_near_drop '{"public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' --accountId --deposit 1 --gas 300000000000000 # create a FT drop - near call create_ft_drop '{"drop_id": "1", "public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' --accountId --gas 300000000000000 + near call create_ft_drop '{"public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' --accountId --gas 300000000000000 # create a NFT drop - near call create_nft_drop '{"drop_id": "1", "public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' --accountId --gas 300000000000000 + near call create_nft_drop '{"public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' --accountId --gas 300000000000000 # claim to an existing account # see the full version @@ -198,13 +200,13 @@ To interact with the contract through the console, you can use the following com ```bash # create a NEAR drop - near contract call-function as-transaction create_near_drop json-args '{"drop_id": "1", "public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' prepaid-gas '300.0 Tgas' attached-deposit '1 NEAR' sign-as network-config testnet sign-with-keychain send + near contract call-function as-transaction create_near_drop json-args '{"public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' prepaid-gas '300.0 Tgas' attached-deposit '1 NEAR' sign-as network-config testnet sign-with-keychain send # create a FT drop - near contract call-function as-transaction create_ft_drop json-args '{"drop_id": "1", "public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send + near contract call-function as-transaction create_ft_drop json-args '{"public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send # create a NFT drop - near contract call-function as-transaction create_nft_drop json-args '{"drop_id": "1", "public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send + near contract call-function as-transaction create_nft_drop json-args '{"public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send # claim to an existing account near contract call-function as-transaction claim_for json-args '{"account_id": ""}' prepaid-gas '30.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-plaintext-private-key --signer-public-key ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q --signer-private-key ed25519:3yVFxYtyk7ZKEMshioC3BofK8zu2q6Y5hhMKHcV41p5QchFdQRzHYUugsoLtqV3Lj4zURGYnHqMqt7zhZZ2QhdgB send From ca6be2f7dfe1f29e5f9216a050ceb995ebc40ad0 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Fri, 10 Jan 2025 13:05:42 +0100 Subject: [PATCH 5/7] fix code links --- docs/3.tutorials/examples/near-drop.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/3.tutorials/examples/near-drop.md b/docs/3.tutorials/examples/near-drop.md index 260cff00a2..09ef8d398f 100644 --- a/docs/3.tutorials/examples/near-drop.md +++ b/docs/3.tutorials/examples/near-drop.md @@ -27,9 +27,9 @@ Particularly, it shows: - `drop_id_by_key` - that LookupMap structure contains relations between `PublicKey` and `DropId`. `PublicKey` is used to claim drop. `DropId` is a unique identificator by which you can get drop's data like amount of tokens to drop, FT or NFT contract, etc. - `drop_by_id` - that LookupMap structure contains relations between `DropId` and actual drop data - `Drop`. - + start="22" end="29" /> --- @@ -64,13 +64,13 @@ Creating drop functions looks very similar, the main difference is in the struct + start="44" end="66" /> + start="68" end="89" /> + start="91" end="103" /> From 703b8ed6ece0b11c33e69c89ea17b2cf9d7674f2 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Fri, 10 Jan 2025 15:15:03 +0100 Subject: [PATCH 6/7] fix max gas --- docs/3.tutorials/examples/near-drop.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/3.tutorials/examples/near-drop.md b/docs/3.tutorials/examples/near-drop.md index 09ef8d398f..7d17101c06 100644 --- a/docs/3.tutorials/examples/near-drop.md +++ b/docs/3.tutorials/examples/near-drop.md @@ -200,19 +200,19 @@ To interact with the contract through the console, you can use the following com ```bash # create a NEAR drop - near contract call-function as-transaction create_near_drop json-args '{"public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' prepaid-gas '300.0 Tgas' attached-deposit '1 NEAR' sign-as network-config testnet sign-with-keychain send + near contract call-function as-transaction create_near_drop json-args '{"public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' prepaid-gas '100.0 Tgas' attached-deposit '1 NEAR' sign-as network-config testnet sign-with-keychain send # create a FT drop - near contract call-function as-transaction create_ft_drop json-args '{"public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send + near contract call-function as-transaction create_ft_drop json-args '{"public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send # create a NFT drop - near contract call-function as-transaction create_nft_drop json-args '{"public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send + near contract call-function as-transaction create_nft_drop json-args '{"public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-keychain send # claim to an existing account near contract call-function as-transaction claim_for json-args '{"account_id": ""}' prepaid-gas '30.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-plaintext-private-key --signer-public-key ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q --signer-private-key ed25519:3yVFxYtyk7ZKEMshioC3BofK8zu2q6Y5hhMKHcV41p5QchFdQRzHYUugsoLtqV3Lj4zURGYnHqMqt7zhZZ2QhdgB send # claim to a new account - near contract call-function as-transaction create_account_and_claim json-args '{"account_id": ""}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-plaintext-private-key --signer-public-key ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4 --signer-private-key ed25519:2xZcegrZvP52VrhehvApnx4McL85hcSBq1JETJrjuESC6v6TwTcr4VVdzxaCReyMCJvx9V4X1ppv8cFFeQZ6hJzU send + near contract call-function as-transaction create_account_and_claim json-args '{"account_id": ""}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as network-config testnet sign-with-plaintext-private-key --signer-public-key ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4 --signer-private-key ed25519:2xZcegrZvP52VrhehvApnx4McL85hcSBq1JETJrjuESC6v6TwTcr4VVdzxaCReyMCJvx9V4X1ppv8cFFeQZ6hJzU send ``` From f958ccc3373c97823162b863453a816a2777da5c Mon Sep 17 00:00:00 2001 From: garikbesson Date: Fri, 10 Jan 2025 15:23:47 +0100 Subject: [PATCH 7/7] fix max gas 2 --- docs/3.tutorials/examples/near-drop.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/3.tutorials/examples/near-drop.md b/docs/3.tutorials/examples/near-drop.md index 7d17101c06..2e228c497e 100644 --- a/docs/3.tutorials/examples/near-drop.md +++ b/docs/3.tutorials/examples/near-drop.md @@ -180,13 +180,13 @@ To interact with the contract through the console, you can use the following com ```bash # create a NEAR drop - near call create_near_drop '{"public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' --accountId --deposit 1 --gas 300000000000000 + near call create_near_drop '{"public_keys": ["ed25519:AvBVZDQrg8pCpEDFUpgeLYLRGUW8s5h57NGhb1Tc4H5q", "ed25519:4FMNvbvU4epP3HL9mRRefsJ2tMECvNLfAYDa9h8eUEa4"], "amount_per_drop": "10000000000000000000000"}' --accountId --deposit 1 --gas 100000000000000 # create a FT drop - near call create_ft_drop '{"public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' --accountId --gas 300000000000000 + near call create_ft_drop '{"public_keys": ["ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "ed25519:5oN7Yk7FKQMKpuP4aroWgNoFfVDLnY3zmRnqYk9fuEvR"], "amount_per_drop": "1", "ft_contract": ""}' --accountId --gas 100000000000000 # create a NFT drop - near call create_nft_drop '{"public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' --accountId --gas 300000000000000 + near call create_nft_drop '{"public_key": "ed25519:HcwvxZXSCX341Pe4vo9FLTzoRab9N8MWGZ2isxZjk1b8", "nft_contract": ""}' --accountId --gas 100000000000000 # claim to an existing account # see the full version