-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathwithdraw.rs
More file actions
40 lines (33 loc) · 1.13 KB
/
Copy pathwithdraw.rs
File metadata and controls
40 lines (33 loc) · 1.13 KB
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
mod support;
use anyhow::{Error, Result};
use dydx::config::ClientConfig;
use dydx::node::{NodeClient, Wallet};
use support::constants::TEST_MNEMONIC;
pub struct Transferor {
client: NodeClient,
wallet: Wallet,
}
impl Transferor {
pub async fn connect() -> Result<Self> {
// Initialize rustls crypto provider
support::crypto::init_crypto_provider();
let config = ClientConfig::from_file("client/tests/testnet.toml").await?;
let client = NodeClient::connect(config.node).await?;
let wallet = Wallet::from_mnemonic(TEST_MNEMONIC)?;
Ok(Self { client, wallet })
}
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt().try_init().map_err(Error::msg)?;
let mut transferor = Transferor::connect().await?;
let mut account = transferor.wallet.account(0, &mut transferor.client).await?;
let recipient = account.address().clone();
let sender = account.subaccount(0)?;
let tx_hash = transferor
.client
.withdraw(&mut account, sender, recipient, 1)
.await?;
tracing::info!("Withdraw transaction hash: {:?}", tx_hash);
Ok(())
}