-
Notifications
You must be signed in to change notification settings - Fork 4
Global contract examples (rust) #8
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1d386ba
global contract example
bucanero adcbba9
update
bucanero fc53164
Update Cargo.toml
bucanero 154da91
fix path
bucanero bf025d5
Merge branch 'main' into add-global-rs
bucanero e828486
fix
bucanero cb33908
use .env
bucanero 02f3288
create new account
bucanero 68ab4e9
Update global_contract_hash.rs
bucanero 78f8f7e
Update global_contract_hash.rs
bucanero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use near_api::*; | ||
use near_primitives::views::FinalExecutionOutcomeView; | ||
|
||
/// Example deploying a contract to the global contract code storage as account-id | ||
#[tokio::main] | ||
async fn main() { | ||
let global_account_id: AccountId = "nft-contract.testnet".parse().unwrap(); | ||
let global_code = std::fs::read("path/to/your/contract.wasm").unwrap(); | ||
bucanero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let global_signer = Signer::new(Signer::from_ledger()).unwrap(); | ||
|
||
// Deploy the global contract code using the account ID `nft-contract.testnet` | ||
// This will deploy the contract to the specified account ID | ||
// and return the final execution outcome | ||
let result: FinalExecutionOutcomeView = Contract::deploy_global_contract_code(global_code) | ||
denbite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.as_account_id(global_account_id.clone()) | ||
.with_signer(global_signer) | ||
.send_to_testnet() | ||
.await.unwrap(); | ||
|
||
println!("{:?}", result); | ||
|
||
// Prepare a transaction to deploy a contract to the provided account using a mutable account-id reference to the code from the global contract code storage. | ||
// This is useful for deploying contracts that are meant to be used by multiple accounts or for creating a contract that can be updated later. | ||
// | ||
// Please note that you have to trust the account-id that you are providing. As the code is mutable, the owner of the referenced account can | ||
// change the code at any time which might lead to unexpected behavior or malicious activity. | ||
let my_account_id: AccountId = "my-contract.testnet".parse().unwrap(); | ||
bucanero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let my_signer = Signer::new(Signer::from_ledger()).unwrap(); | ||
|
||
let result: FinalExecutionOutcomeView = Contract::deploy(my_account_id) | ||
.use_global_account_id(global_account_id) | ||
.without_init_call() | ||
.with_signer(my_signer) | ||
.send_to_testnet() | ||
.await.unwrap(); | ||
|
||
println!("{:?}", result); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use near_api::*; | ||
use near_primitives::views::FinalExecutionOutcomeView; | ||
|
||
/// Example deploying a contract to the global contract code storage as hash | ||
#[tokio::main] | ||
async fn main() { | ||
let account_id: AccountId = "my-account.testnet".parse().unwrap(); | ||
bucanero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let code = std::fs::read("path/to/your/contract.wasm").unwrap(); | ||
bucanero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let signer = Signer::new(Signer::from_ledger()).unwrap(); | ||
|
||
// Deploy the global contract code using a hash | ||
// This will deploy the contract to the global contract hash | ||
// and return the final execution outcome | ||
let result: FinalExecutionOutcomeView = Contract::deploy_global_contract_code(code) | ||
.as_hash() | ||
.with_signer(account_id, signer) | ||
.send_to_testnet() | ||
.await.unwrap(); | ||
|
||
println!("{:?}", result); | ||
|
||
// Prepare a transaction to deploy a contract to the provided account using an immutable hash reference to the code from the global contract code storage. | ||
let global_hash: types::CryptoHash = "DxfRbrjT3QPmoANMDYTR6iXPGJr7xRUyDnQhcAWjcoFF".parse().unwrap(); | ||
let my_account_id: AccountId = "my-contract.testnet".parse().unwrap(); | ||
bucanero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let my_signer = Signer::new(Signer::from_ledger()).unwrap(); | ||
|
||
let result: FinalExecutionOutcomeView = Contract::deploy(my_account_id) | ||
.use_global_hash(global_hash) | ||
.without_init_call() | ||
.with_signer(my_signer) | ||
.send_to_testnet() | ||
.await.unwrap(); | ||
|
||
println!("{:?}", result); | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.