Skip to content

Commit b6cad50

Browse files
committed
update
1 parent 0c9a344 commit b6cad50

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

docs/smart-contracts/global-contracts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ When using a reference **by hash**, you reference the global contract by its imm
3030

3131
Global contracts can be deployed in 2 ways: either by their hash or by the owner account ID.
3232
Contracts deployed by hash are effectively immutable and cannot be updated.
33-
When deployed by account id the owner can redeploy the contract updating it for all its users.
33+
When deployed by account ID the owner can redeploy the contract updating it for all its users.
3434

3535
Global contracts can be deployed using `NEAR CLI`.
3636
The process is similar to [deploying a regular contract](./release/deploy.md#deploying-the-contract) but `deploy-as-global` command should be used instead of `deploy`.

docs/tools/near-api.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,90 @@ There are two ways to reference a global contract:
12351235
</TabItem>
12361236
</Tabs>
12371237
1238+
</TabItem>
1239+
1240+
<TabItem value="rust" label="🦀 Rust">
1241+
1242+
<Tabs>
1243+
<TabItem value="account" label="By Account" default>
1244+
1245+
Let’s look at an example of deploying a global contract by account.
1246+
1247+
To do this, use the `deploy_global_contract_code` function and use the method `as_account_id`, along with the contract’s code bytes.
1248+
1249+
```rust
1250+
let global_account_id: AccountId = "nft-contract.testnet".parse().unwrap();
1251+
let code = std::fs::read("path/to/your/contract.wasm").unwrap();
1252+
let signer = Signer::new(Signer::from_ledger()).unwrap();
1253+
1254+
let result: FinalExecutionOutcomeView = Contract::deploy_global_contract_code(code)
1255+
.as_account_id(global_account_id)
1256+
.with_signer(signer)
1257+
.send_to_testnet()
1258+
.await.unwrap();
1259+
```
1260+
1261+
Once the global contract is deployed, let’s see how an end user can reference and use it in their own account. To do this, they need to call the `use_global_account_id` function and pass the source `accountId` where the contract was originally deployed.
12381262
1263+
```rust
1264+
let global_account_id: AccountId = "nft-contract.testnet".parse().unwrap();
1265+
let my_account_id: AccountId = "my-contract.testnet".parse().unwrap();
1266+
let my_signer = Signer::new(Signer::from_ledger()).unwrap();
1267+
1268+
let result: FinalExecutionOutcomeView = Contract::deploy(my_account_id)
1269+
.use_global_account_id(global_account_id)
1270+
.without_init_call()
1271+
.with_signer(my_signer)
1272+
.send_to_testnet()
1273+
.await.unwrap();
1274+
```
12391275
1276+
<a href="https://github.com/near-examples/near-api-examples/blob/adcbba98c0a957bbd3c8146e108dfefa8ed72465/rust/examples/global_contract_accountid.rs" target="_blank" rel="noreferrer noopener" class="text-center">
1277+
See full example on GitHub
1278+
</a>
12401279
</TabItem>
1280+
1281+
<TabItem value="hash" label="By Hash" default>
1282+
1283+
Let’s look at an example of deploying a global contract by hash.
1284+
1285+
To do this, use the `deploy_global_contract_code` function and use the method `as_hash`, along with the contract’s code bytes.
1286+
1287+
```rust
1288+
let account_id: AccountId = "my-account.testnet".parse().unwrap();
1289+
let code = std::fs::read("path/to/your/contract.wasm").unwrap();
1290+
let signer = Signer::new(Signer::from_ledger()).unwrap();
1291+
1292+
let result: FinalExecutionOutcomeView = Contract::deploy_global_contract_code(code)
1293+
.as_hash()
1294+
.with_signer(account_id, signer)
1295+
.send_to_testnet()
1296+
.await.unwrap();
1297+
```
1298+
1299+
Once the global contract is deployed, let’s see how an end user can reference and use it in their own account. To do this, they need to call the `use_global_hash` function and pass the source `hash` of the original contract.
1300+
1301+
```rust
1302+
let global_hash: types::CryptoHash = "DxfRbrjT3QPmoANMDYTR6iXPGJr7xRUyDnQhcAWjcoFF".parse().unwrap();
1303+
let account_id: AccountId = "my-contract.testnet".parse().unwrap();
1304+
let signer = Signer::new(Signer::from_ledger()).unwrap();
1305+
1306+
let result: FinalExecutionOutcomeView = Contract::deploy(account_id)
1307+
.use_global_hash(global_hash)
1308+
.without_init_call()
1309+
.with_signer(signer)
1310+
.send_to_testnet()
1311+
.await.unwrap();
1312+
```
1313+
1314+
<a href="https://github.com/near-examples/near-api-examples/blob/adcbba98c0a957bbd3c8146e108dfefa8ed72465/rust/examples/global_contract_hash.rs" target="_blank" rel="noreferrer noopener" class="text-center">
1315+
See full example on GitHub
1316+
</a>
1317+
</TabItem>
1318+
</Tabs>
1319+
1320+
</TabItem>
1321+
12411322
</Tabs>
12421323
12431324
---

0 commit comments

Comments
 (0)