Skip to content

Commit

Permalink
chore: add sign_deploy_contract example
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 29, 2024
1 parent 96d5eb2 commit 740b45c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ path = "examples/sign_transaction/add_key_fullaccess.rs"
name = "sign_add_key_functioncall"
path = "examples/sign_transaction/add_key_functioncall.rs"

[[example]]
name = "sign_deploy_contract"
path = "examples/sign_transaction/deploy_contract.rs"


[[example]]
name = "blind_sign_transaction"

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ RUST_LOG=sign_add_key_fullaccess,near_ledger=info cargo run --example sign_add_k
RUST_LOG=sign_add_key_functioncall,near_ledger=info cargo run --example sign_add_key_functioncall
```

#### Deploy contract

```bash
RUST_LOG=sign_deploy_contract,near_ledger=info cargo run --example sign_deploy_contract
```

#### Transfer

```bash
Expand Down
23 changes: 23 additions & 0 deletions examples/sign_transaction/deploy_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use near_ledger::NEARLedgerError;
use near_primitives::transaction::DeployContractAction;
use near_primitives_core::hash::CryptoHash;

#[path = "../common/lib.rs"]
mod common;

fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction {
let mut tx = common::tx_template(ledger_pub_key);

let code = core::iter::repeat(42u8).take(300).collect::<Vec<_>>();

let code_hash = CryptoHash::hash_bytes(&code);
println!("Contract code hash: {:?}", code_hash);
tx.actions = vec![near_primitives::transaction::Action::DeployContract(
DeployContractAction { code },
)];
tx
}

fn main() -> Result<(), NEARLedgerError> {
common::get_key_sign_and_verify_flow(tx)
}

0 comments on commit 740b45c

Please sign in to comment.