-
Notifications
You must be signed in to change notification settings - Fork 3
/
account_deposit.rs
51 lines (42 loc) · 1.54 KB
/
account_deposit.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2024 ADM Contributors
// SPDX-License-Identifier: Apache-2.0, MIT
use std::env;
use anyhow::anyhow;
use ethers::utils::hex::ToHexExt;
use fvm_shared::econ::TokenAmount;
use adm_sdk::{account::Account, network::Network};
use adm_signer::{key::parse_secret_key, AccountKind, Signer, Wallet};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
return Err(anyhow!("missing hex-encoded private key"));
}
let pk_kex = &args[1];
let pk = parse_secret_key(pk_kex)?;
// Use testnet network defaults
// Note: The debit account _must_ hold at least 1 Calibration tFIL for the deposit
// plus enough to cover the transaction fee.
// Go to the faucet at https://faucet.calibnet.chainsafe-fil.io/ to get yourself some tFIL.
let network = Network::Testnet.init();
// Setup local wallet using private key from arg
let signer = Wallet::new_secp256k1(pk, AccountKind::Ethereum, network.subnet_id()?.parent()?)?;
// Deposit some calibration funds into the subnet
// Note: The debit account _must_ have Calibration
let tx = Account::deposit(
&signer,
signer.address(),
network.parent_subnet_config(Default::default())?,
TokenAmount::from_whole(1),
)
.await?;
println!(
"Deposited 1 tFIL to {}",
signer.evm_address()?.encode_hex_with_prefix()
);
println!(
"Transaction hash: 0x{}",
hex::encode(tx.transaction_hash.to_fixed_bytes())
);
Ok(())
}