|
| 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