Skip to content

Commit

Permalink
Added Tabs for both near-cli-rs and near-cli commands (#1480)
Browse files Browse the repository at this point in the history
* Update deploy.md

* Update lock.md

* Update upgrade.md

* Update prototyping.md

* Update token-tx.md

* Update prototyping.md

* Update serialization-interface.md

* Update token-tx.md

---------

Co-authored-by: gagdiez <[email protected]>
  • Loading branch information
ghimire007 and gagdiez authored Sep 29, 2023
1 parent f7a78c2 commit e6b571d
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 10 deletions.
92 changes: 92 additions & 0 deletions docs/2.develop/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ id: deploy
title: NEAR CLI - Basics
sidebar_label: Deploying and Using
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

After your contract is ready you can deploy it in the NEAR network for everyone to use it.

Expand All @@ -24,6 +26,11 @@ Thanks to the `NEAR CLI` deploying a contract is as simple as:
2. Deploy it into the desired account using the [NEAR CLI](../4.tools/cli.md#near-deploy):

#### Create an Account and Deploy


<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Near-CLI">

```bash
# Automatically deploy the wasm in a new account
near dev-deploy <route_to_wasm>
Expand All @@ -32,7 +39,27 @@ near dev-deploy <route_to_wasm>
cat ./neardev/dev-account
```

</TabItem>
<TabItem value="Near-CLI-rs">

```bash
# Automatically deploy the wasm in a new account
near account create-account sponsor-by-faucet-service <my-new-dev-account>.testnet autogenerate-new-keypair save-to-keychain network-config testnet create


near contract deploy <my-new-dev-account>.testnet use-file <route_to_wasm> without-init-call network-config testnet sign-with-keychain
```

</TabItem>
</Tabs>



#### Deploy in an Existing Account

<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Near-CLI">

```bash
# login into your account
near login
Expand All @@ -41,6 +68,21 @@ near login
near deploy <accountId> <route_to_wasm>
```

</TabItem>
<TabItem value="Near-CLI-rs">

```bash
# login into your account
near account import-account using-web-wallet network-config testnet

# deploy the contract
near contract deploy <accountId> use-file <route_to_wasm> without-init-call network-config testnet sign-with-keychain send

```

</TabItem>
</Tabs>

:::tip
You can overwrite a contract by deploying another on top of it. In this case, the account's logic
will change, but the state will persist
Expand All @@ -62,10 +104,29 @@ Considering this, we advise to name methods using `snake_case` in all SDKs as th
If your contract has an [initialization method](./contracts/anatomy.md#initialization-functions) you can call it to
initialize the state. This is not necessary if your contract implements `default` values for the state.



<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Near-CLI">

```bash
# Call the initialization method (`init` in our examples)
near call <contractId> <initMethod> [<args>] --accountId <accountId>
```
</TabItem>
<TabItem value="Near-CLI-rs">


```bash
# Call the initialization method (`init` in our examples)
near contract call-function as-transaction <contractId> <initMethod> json-args [<args>] prepaid-gas '30 TeraGas' attached-deposit '0 NEAR' sign-as <accountId> network-config testnet sign-with-keychain send
```

</TabItem>
</Tabs>




:::info
You can initialize your contract [during deployment](#deploying-the-contract) using the `--initFunction` & `--initArgs` arguments.
Expand All @@ -81,9 +142,24 @@ Once your contract is deployed you can interact with it right away using [NEAR C
### View methods
View methods are those that perform **read-only** operations. Calling these methods is free, and do not require to specify which account is being used to make the call:




<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Near-CLI">

```bash
near view <contractId> <methodName>
```
</TabItem>

<TabItem value="Near-CLI-rs">

```bash
near contract call-function as-read-only <contractId> <methodName> text-args '' network-config testnet now
```
</TabItem>
</Tabs>

:::tip
View methods have by default 200 TGAS for execution
Expand All @@ -95,6 +171,22 @@ View methods have by default 200 TGAS for execution
Change methods are those that perform both read and write operations. For these methods we do need to specify the account being used to make the call,
since that account will expend GAS in the call.


<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Near-CLI">

```bash
near call <contractId> <methodName> <jsonArgs> --accountId <yourAccount> [--deposit <amount>] [--gas <GAS>]
```

</TabItem>

<TabItem value="Near-CLI-rs">

```bash

near contract call-function as-transaction <AccountId> <MethodName> json-args <JsonArgs> prepaid-gas <PrepaidGas> attached-deposit <AttachedDeposit> sign-as <AccountId> network-config testnet sign-with-keychain send
```

</TabItem>
</Tabs>
30 changes: 30 additions & 0 deletions docs/2.develop/lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,47 @@ id: lock
title: Locking Accounts
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Removing all [full access keys](../4.tools/cli.md#near-delete-key-near-delete-key) from an account will effectively **lock it**.

When an account is locked nobody can perform transactions in the account's name (e.g. update the code or transfer money).

#### How to Lock an Account
<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Near-CLI">

```bash
near keys <dev-account>
# result: [access_key: {"nonce": ..., "public_key": '<key>'}]

near delete-key <dev-account> '<key>'
```
</TabItem>
<TabItem value="Near-CLI-rs">

```bash
near account list-keys <dev-account> network-config testnet now
# result:

+---+------------+-------+-------------+
| # | Public Key | Nonce | Permissions |
+---+------------+-------+-------------+
.. '<key>' ... ...
+---+------------+-------+-------------+

near account delete-key <dev-account> '<key>' network-config testnet sign-with-keychain send

```



</TabItem>
</Tabs>




#### Why Locking an Account
Locking an account brings more reassurance to end-users, since they know no external actor will be able to manipulate the account's
Expand Down
45 changes: 42 additions & 3 deletions docs/2.develop/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Contract's can be updated in two ways:
## Updating Through Tools
Simply re-deploy another contract using your preferred tool, for example, using [NEAR CLI](../4.tools/cli.md):


<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Near-CLI">

```bash
# If you already used dev-deploy the same account will be used
near dev-deploy --wasmFile <new-contract>
Expand All @@ -28,6 +32,28 @@ near dev-deploy --wasmFile <new-contract>
near deploy <account-id> --wasmFile <new-contract>
```



</TabItem>
<TabItem value="Near-CLI-rs">


```bash
# If you already used dev-deploy the same account will be used
near contract deploy <my-new-dev-account>.testnet use-file <route_to_wasm> without-init-call network-config testnet sign-with-keychain


# If you logged in
near contract deploy <accountId> use-file <route_to_wasm> without-init-call network-config testnet sign-with-keychain send

```


</TabItem>
</Tabs>



---

## Programmatic Update
Expand All @@ -45,7 +71,7 @@ A smart contract can also update itself by implementing a method that:

#### How to Invoke Such Method?
<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Terminal">
<TabItem value="Near-CLI">

```bash
# Load the contract's raw bytes
Expand All @@ -56,7 +82,20 @@ near call <contract-account> update_contract "$CONTRACT_BYTES" --base64 --accoun
```

</TabItem>
<TabItem value="🌐 JavaScript">

<TabItem value="Near-CLI-rs">

```bash
# Load the contract's raw bytes
CONTRACT_BYTES=`cat ./path/to/wasm.wasm | base64`

# Call the update_contract method
near contract call-function as-transaction <contract-account> update_contract base64-args "$CONTRACT_BYTES" prepaid-gas '300 TeraGas' attached-deposit '0 NEAR' sign-as <manager-account> network-config testnet sign-with-keychain send

```

</TabItem>
<TabItem value="🌐 JavaScript">

```js
// Load the contract's raw bytes
Expand Down Expand Up @@ -151,4 +190,4 @@ Notice that `migrate` is actually an [initialization method](./contracts/anatomy

:::tip
You can follow a migration step by step in the [official migration example](https://github.com/near-examples/update-migrate-rust/tree/main/contracts/basic-updates/base)
:::
:::
Loading

0 comments on commit e6b571d

Please sign in to comment.