Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Formatting #1508

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 57 additions & 71 deletions docs/2.develop/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,53 @@ Thanks to the `NEAR CLI` deploying a contract is as simple as:


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

```bash
# Automatically deploy the wasm in a new account
near dev-deploy <route_to_wasm>
```bash
# Automatically deploy the wasm in a new account
near dev-deploy <route_to_wasm>

# Get the account name
cat ./neardev/dev-account
```
# Get the account name
cat ./neardev/dev-account
```

</TabItem>
<TabItem value="Near-CLI-rs">
<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
```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
```
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">
<TabItem value="near-cli">

```bash
# login into your account
near login
```bash
# login into your account
near login

# deploy the contract
near deploy <accountId> <route_to_wasm>
```
# deploy the contract
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
<TabItem value="near-cli-rs">

# deploy the contract
near contract deploy <accountId> use-file <route_to_wasm> without-init-call network-config testnet sign-with-keychain send
```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>
Expand All @@ -104,30 +101,25 @@ 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">
<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 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
```
```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>
</TabItem>
</Tabs>




:::info
You can initialize your contract [during deployment](#deploying-the-contract) using the `--initFunction` & `--initArgs` arguments.
:::
Expand All @@ -142,22 +134,19 @@ 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">
<TabItem value="near-cli">

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

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

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

Expand All @@ -171,22 +160,19 @@ 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">
<TabItem value="near-cli">

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

</TabItem>
<TabItem value="near-cli-rs">

<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
```
```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>
</Tabs>
46 changes: 20 additions & 26 deletions docs/2.develop/lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,37 @@ When an account is locked nobody can perform transactions in the account's name

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

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

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

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

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

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

```



</TabItem>
</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
contract or balance.

:::tip Upgrading Locked Contracts
Please do note that, while no external actor can update the contract, the contract **can still upgrade itself**. See [this article](upgrade.md#programmatic-update) for details.
:::
:::
88 changes: 37 additions & 51 deletions docs/2.develop/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,30 @@ 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>

# If you logged in
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
<TabItem value="near-cli">

```bash
# If you already used dev-deploy the same account will be used
near dev-deploy --wasmFile <new-contract>

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

</TabItem>
# 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 @@ -71,40 +61,37 @@ 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="Near-CLI">
<TabItem value="near-cli">

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

# Call the update_contract method
near call <contract-account> update_contract "$CONTRACT_BYTES" --base64 --accountId <manager-account> --gas 300000000000000
```
# Call the update_contract method
near call <contract-account> update_contract "$CONTRACT_BYTES" --base64 --accountId <manager-account> --gas 300000000000000
```

</TabItem>
<TabItem value="near-cli-rs">

<TabItem value="Near-CLI-rs">
```bash
# Load the contract's raw bytes
CONTRACT_BYTES=`cat ./path/to/wasm.wasm | base64`

```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

```
# 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">
<TabItem value="🌐 JavaScript">

```js
// Load the contract's raw bytes
const code = fs.readFileSync("./path/to/wasm.wasm");

// Call the update_contract method
await wallet.callMethod({contractId: guestBook, method: "update_contract", args: code, gas: "300000000000000"});
```
```js
// Load the contract's raw bytes
const code = fs.readFileSync("./path/to/wasm.wasm");

// Call the update_contract method
await wallet.callMethod({contractId: guestBook, method: "update_contract", args: code, gas: "300000000000000"});
```
</TabItem>
</Tabs>

Expand Down Expand Up @@ -138,7 +125,6 @@ If you have no option but to migrate the state, then you need to implement a met
This is how DAOs [update themselves](https://github.com/near-daos/sputnik-dao-contract/blob/main/sputnikdao2/src/upgrade.rs#L59)
:::


<hr class="subsection" />

### Example: Guest Book Migration
Expand Down
Loading