Skip to content

Commit

Permalink
Update prototyping.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ghimire007 authored Sep 4, 2023
1 parent df55d36 commit a11c7c3
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions docs/sdk/rust/building/prototyping.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sidebar_label: Rapid Prototyping
title: "Upgrading Contracts: Rapid Prototyping"
---
import {CodeTabs, Language, Github} from "@site/components/codetabs";
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Rapid Prototyping

Expand Down Expand Up @@ -42,11 +44,24 @@ The [rust-status-message](https://github.com/near-examples/rust-status-message)

Let's say you deploy this contract to testnet, then call it with:

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

```bash
near call [contract] set_status '{"message": "lol"}' --accountId you.testnet
near view [contract] get_status '{"account_id": "you.testnet"}'
```

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

```bash
near contract call-function as-transaction [contract] set_status json-args '{"message": "lol"}' prepaid-gas '30 TeraGas' attached-deposit '0 NEAR' sign-as you.testnet network-config testnet sign-with-keychain send

near contract call-function as-read-only [contract] get_status text-args '{"account_id": "you.testnet"}' network-config testnet now
```
</TabItem>
</Tabs>
This will return the message that you set with the call to `set_status`, in this case `"lol"`.

At this point the contract is deployed and has some state.
Expand Down Expand Up @@ -97,10 +112,26 @@ You build & deploy the contract again, thinking that maybe because the new `tagl
### 1. `rm -rf neardev && near dev-deploy`

When first getting started with a new project, the fastest way to deploy a contract is [`dev-deploy`](/concepts/basics/accounts/creating-accounts):
<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="Near-CLI">

```bash
near dev-deploy [--wasmFile ./path/to/compiled.wasm]
```
</TabItem>
<TabItem value="Near-CLI-rs">

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

This does a few things:

Expand All @@ -119,21 +150,58 @@ The easiest way is just to delete the `neardev` folder, then run `near dev-deplo

If you want to have a predictable account name rather than an ever-changing `dev-*` account, the best way is probably to create a sub-account:

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

```bash title="Create sub-account"
near create-account app-name.you.testnet --masterAccount you.testnet
```
</TabItem>
<TabItem value="Near-CLI-rs">

```bash title="Create sub-account"
near account create-account fund-myself app-name.you.testnet '100 NEAR' autogenerate-new-keypair save-to-keychain sign-as you.testnet network-config testnet sign-with-keychain send
```

</TabItem>
</Tabs>

Then deploy your contract to it:

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

```bash title="Deploy to sub-account"
near deploy --accountId app-name.you.testnet [--wasmFile ./path/to/compiled.wasm]
```
</TabItem>
<TabItem value="Near-CLI-rs">

```bash title="Deploy to sub-account"
near contract deploy app-name.you.testnet use-file <./path/to/compiled.wasm> without-init-call network-config testnet sign-with-keychain send
```

</TabItem>
</Tabs>


In this case, how do you delete all contract state and start again? Delete the sub-account and recreate it.


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

```bash title="Delete sub-account"
near delete app-name.you.testnet you.testnet
```
</TabItem>
<TabItem value="Near-CLI-rs">

```bash title="Delete sub-account"
near account delete-account app-name.you.testnet beneficiary you.testnet network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>

This sends all funds still on the `app-name.you.testnet` account to `you.testnet` and deletes the contract that had been deployed to it, including all contract state.

Expand Down

0 comments on commit a11c7c3

Please sign in to comment.