-
Notifications
You must be signed in to change notification settings - Fork 29
/
sudt_issue.rs
45 lines (36 loc) · 1.74 KB
/
sudt_issue.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
use ckb_sdk::{
transaction::{
builder::{sudt::SudtTransactionBuilder, CkbTransactionBuilder},
input::InputIterator,
signer::{SignContexts, TransactionSigner},
TransactionBuilderConfiguration,
},
Address, CkbRpcClient, NetworkInfo,
};
use ckb_types::h256;
use std::{error::Error as StdErr, str::FromStr};
fn main() -> Result<(), Box<dyn StdErr>> {
let network_info = NetworkInfo::testnet();
let configuration = TransactionBuilderConfiguration::new_with_network(network_info.clone())?;
let issuer = Address::from_str("ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2qf8keemy2p5uu0g0gn8cd4ju23s5269qk8rg4r")?;
let iterator = InputIterator::new_with_address(&[issuer.clone()], &network_info);
let mut builder = SudtTransactionBuilder::new(configuration, iterator, &issuer, true)?;
builder.add_output(&issuer, 42);
let mut tx_with_groups = builder.build(&Default::default())?;
let json_tx = ckb_jsonrpc_types::TransactionView::from(tx_with_groups.get_tx_view().clone());
println!("tx: {}", serde_json::to_string_pretty(&json_tx).unwrap());
let private_keys = vec![h256!(
"0x6c9ed03816e3111e49384b8d180174ad08e29feb1393ea1b51cef1c505d4e36a"
)];
TransactionSigner::new(&network_info).sign_transaction(
&mut tx_with_groups,
&SignContexts::new_sighash_h256(private_keys)?,
)?;
let json_tx = ckb_jsonrpc_types::TransactionView::from(tx_with_groups.get_tx_view().clone());
println!("tx: {}", serde_json::to_string_pretty(&json_tx).unwrap());
let tx_hash = CkbRpcClient::new(network_info.url.as_str())
.send_transaction(json_tx.inner, None)
.expect("send transaction");
println!(">>> tx {} sent! <<<", tx_hash);
Ok(())
}