Skip to content

Commit

Permalink
fix (#2220)
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero authored Aug 30, 2024
1 parent 5ff74e7 commit 6374522
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 132 deletions.
145 changes: 80 additions & 65 deletions docs/2.build/2.smart-contracts/release/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
id: upgrade
title: Updating Contracts
---

import {CodeTabs, Language, Github} from "@site/src/components/codetabs";
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
Expand All @@ -23,25 +22,27 @@ Simply re-deploy another contract using your preferred tool, for example, using
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">

```bash
# (optional) If you don't have an account, create one
near create-account <account-id> --useFaucet
```bash
# (optional) If you don't have an account, create one
near create-account <account-id> --useFaucet

# Deploy the contract
near deploy <account-id> <wasm-file>
```

</TabItem>

# Deploy the contract
near deploy <account-id> <wasm-file>
```
</TabItem>
<TabItem value="full" label="Full">

<TabItem value="full" label="Full">
```bash
# (optional) If you don't have an account, create one
near account create-account sponsor-by-faucet-service somrnd.testnet autogenerate-new-keypair save-to-keychain network-config testnet create

```bash
# (optional) If you don't have an account, create one
near account create-account sponsor-by-faucet-service somrnd.testnet autogenerate-new-keypair save-to-keychain network-config testnet create
# Deploy the contract
near contract deploy <accountId> use-file <route_to_wasm> without-init-call network-config testnet sign-with-keychain send
```

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

</Tabs>

Expand All @@ -67,33 +68,37 @@ A smart contract can also update itself by implementing a method that:
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Near CLI (short)">

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

</TabItem>

<TabItem value="full" label="Near CLI (full)">

# Call the update_contract method
near call <contract-account> update_contract "$CONTRACT_BYTES" --base64 --accountId <manager-account> --gas 300000000000000
```
</TabItem>
```bash
# Call the update_contract method
near contract call-function as-transaction <contract-account> update_contract file-args </path/to/wasm.wasm> prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as <manager-account> network-config testnet sign-with-keychain send
```

<TabItem value="full" label="Near CLI (full)">
</TabItem>

```bash
# Call the update_contract method
near contract call-function as-transaction <contract-account> update_contract file-args </path/to/wasm.wasm> prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as <manager-account> network-config testnet sign-with-keychain send
```
</TabItem>
<TabItem value="js" label="🌐 JavaScript">

<TabItem value="js" label="🌐 JavaScript">
```js
// Load the contract's raw bytes
const code = fs.readFileSync("./path/to/wasm.wasm");

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

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

:::tip DAO Factories
Expand Down Expand Up @@ -140,16 +145,19 @@ Imagine you have a Guest Book where you store messages, and the users can pay fo
to be "premium". You keep track of the messages and payments using the following state:

<CodeTabs>
<Language value="js" language="js">
<Github fname="index.js"
url="https://github.com/near/near-sdk-js/blob/develop/examples/src/basic-updates-base.js"
start="16" end="37" />
</Language>
<Language value="js" language="js">

<Language value="rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/update-migrate-rust/blob/main/basic-updates/base/src/lib.rs"
start="10" end="21" />
<Github fname="index.js"
url="https://github.com/near/near-sdk-js/blob/develop/examples/src/basic-updates-base.js"
start="16" end="37" />

</Language>

<Language value="rust" language="rust">

<Github fname="lib.rs"
url="https://github.com/near-examples/update-migrate-rust/blob/main/basic-updates/base/src/lib.rs"
start="10" end="21" />

</Language>

Expand All @@ -161,16 +169,19 @@ At some point you realize that you could keep track of the `payments` inside of
so you change the contract to:

<CodeTabs>
<Language value="js" language="js">
<Github fname="index.js"
url="https://github.com/near/near-sdk-js/blob/develop/examples/src/basic-updates-update.js"
start="23" end="45" />
</Language>
<Language value="js" language="js">

<Language value="rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/update-migrate-rust/blob/main/basic-updates/update/src/lib.rs"
start="12" end="23" />
<Github fname="index.js"
url="https://github.com/near/near-sdk-js/blob/develop/examples/src/basic-updates-update.js"
start="23" end="45" />

</Language>

<Language value="rust" language="rust">

<Github fname="lib.rs"
url="https://github.com/near-examples/update-migrate-rust/blob/main/basic-updates/update/src/lib.rs"
start="12" end="23" />

</Language>

Expand All @@ -189,16 +200,19 @@ To fix the problem, you need to implement a method that goes through the old sta
adds the information to the `PostedMessages`:

<CodeTabs>
<Language value="js" language="js">
<Github fname="index.js"
url="https://github.com/near/near-sdk-js/blob/develop/examples/src/basic-updates-update.js"
start="7" end="70" />
</Language>
<Language value="js" language="js">

<Language value="rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/update-migrate-rust/blob/main/basic-updates/update/src/migrate.rs"
start="3" end="46" />
<Github fname="index.js"
url="https://github.com/near/near-sdk-js/blob/develop/examples/src/basic-updates-update.js"
start="7" end="70" />

</Language>

<Language value="rust" language="rust">

<Github fname="lib.rs"
url="https://github.com/near-examples/update-migrate-rust/blob/main/basic-updates/update/src/migrate.rs"
start="3" end="46" />

</Language>

Expand All @@ -208,6 +222,7 @@ Notice that `migrate` is actually an [initialization method](../anatomy/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/basic-updates/base)
You can follow a migration step by step in the [official migration example](https://github.com/near-examples/update-migrate-rust/tree/main/basic-updates/base)
Javascript migration example testfile can be found on here: [test-basic-updates.ava.js](https://github.com/near/near-sdk-js/blob/develop/examples/__tests__/test-basic-updates.ava.js), run by this command: `pnpm run test:basic-update` in examples directory.

:::
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"wait-on": "^5.2.0"
},
"dependencies": {
"@crowdin/cli": "^3.9.0",
"@crowdin/cli": "^4.1.1",
"@docusaurus/core": "^3.4.0",
"@docusaurus/plugin-ideal-image": "^3.4.0",
"@docusaurus/plugin-sitemap": "^3.4.0",
Expand Down
Loading

0 comments on commit 6374522

Please sign in to comment.