You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/smart-contracts/global-contracts.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ When using a reference **by hash**, you reference the global contract by its imm
30
30
31
31
Global contracts can be deployed in 2 ways: either by their hash or by the owner account ID.
32
32
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.
34
34
35
35
Global contracts can be deployed using `NEAR CLI`.
36
36
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`.
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.
1238
1262
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)
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)
0 commit comments