Skip to content

Commit 36bcc5d

Browse files
authored
feat: signer interactivity (#617)
Makes signer implementations specify whether a signing operation is "interactive" (or just expensive). Utilizing this new information, `Account` and `AccountFactory` now make more informed decisions on whether to request real signatures for different types of operations. The most significant benefit of this change is allowing using hardware wallet without excessive unnecessary signing requests.
1 parent a78cc04 commit 36bcc5d

17 files changed

+347
-85
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ Examples can be found in the [examples folder](./examples):
100100

101101
10. [Deploy an OpenZeppelin account with Ledger](./examples/deploy_account_with_ledger.rs)
102102

103-
11. [Parsing a JSON-RPC request on the server side](./examples/parse_jsonrpc_request.rs)
103+
11. [Transfer ERC20 tokens with Ledger](./examples/transfer_with_ledger.rs)
104104

105-
12. [Inspecting a erased provider-specific error type](./examples/downcast_provider_error.rs)
105+
12. [Parsing a JSON-RPC request on the server side](./examples/parse_jsonrpc_request.rs)
106+
107+
13. [Inspecting a erased provider-specific error type](./examples/downcast_provider_error.rs)
106108

107109
## License
108110

examples/declare_cairo0_contract.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ async fn main() {
4545
.await
4646
.unwrap();
4747

48-
dbg!(result);
48+
println!("Transaction hash: {:#064x}", result.transaction_hash);
49+
println!("Class hash: {:#064x}", result.class_hash);
4950
}

examples/declare_cairo1_contract.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ async fn main() {
5353
.await
5454
.unwrap();
5555

56-
dbg!(result);
56+
println!("Transaction hash: {:#064x}", result.transaction_hash);
57+
println!("Class hash: {:#064x}", result.class_hash);
5758
}

examples/deploy_account_with_ledger.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ async fn main() {
5151
match result {
5252
Ok(tx) => {
5353
println!("Transaction hash: {:#064x}", tx.transaction_hash);
54+
println!("Account: {:#064x}", tx.contract_address);
5455
}
5556
Err(err) => {
5657
eprintln!("Error: {err}");

examples/deploy_argent_account.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async fn main() {
4747
match result {
4848
Ok(tx) => {
4949
println!("Transaction hash: {:#064x}", tx.transaction_hash);
50+
println!("Account: {:#064x}", tx.contract_address);
5051
}
5152
Err(err) => {
5253
eprintln!("Error: {err}");

examples/mint_tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ async fn main() {
5151
.await
5252
.unwrap();
5353

54-
dbg!(result);
54+
println!("Transaction hash: {:#064x}", result.transaction_hash);
5555
}

examples/transfer_with_ledger.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use starknet::{
2+
accounts::{Account, Call, ExecutionEncoding, SingleOwnerAccount},
3+
core::{
4+
chain_id,
5+
types::{BlockId, BlockTag, Felt},
6+
utils::get_selector_from_name,
7+
},
8+
macros::felt,
9+
providers::{
10+
jsonrpc::{HttpTransport, JsonRpcClient},
11+
Url,
12+
},
13+
signers::LedgerSigner,
14+
};
15+
16+
#[tokio::main]
17+
async fn main() {
18+
let provider = JsonRpcClient::new(HttpTransport::new(
19+
Url::parse("https://starknet-sepolia.public.blastapi.io/rpc/v0_7").unwrap(),
20+
));
21+
22+
let signer = LedgerSigner::new(
23+
"m/2645'/1195502025'/1470455285'/0'/0'/0"
24+
.try_into()
25+
.expect("unable to parse path"),
26+
)
27+
.await
28+
.expect("failed to initialize Starknet Ledger app");
29+
let address = Felt::from_hex("YOUR_ACCOUNT_CONTRACT_ADDRESS_IN_HEX_HERE").unwrap();
30+
let eth_token_address =
31+
Felt::from_hex("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7")
32+
.unwrap();
33+
34+
let mut account = SingleOwnerAccount::new(
35+
provider,
36+
signer,
37+
address,
38+
chain_id::SEPOLIA,
39+
ExecutionEncoding::New,
40+
);
41+
42+
// `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest
43+
// block. Optionally change the target block to pending with the following line:
44+
account.set_block_id(BlockId::Tag(BlockTag::Pending));
45+
46+
let result = account
47+
.execute_v1(vec![Call {
48+
to: eth_token_address,
49+
selector: get_selector_from_name("transfer").unwrap(),
50+
calldata: vec![felt!("0x1234"), felt!("100"), Felt::ZERO],
51+
}])
52+
.send()
53+
.await
54+
.unwrap();
55+
56+
println!("Transaction hash: {:#064x}", result.transaction_hash);
57+
}

0 commit comments

Comments
 (0)