Crates.io | sui-rust-operator |
lib.rs | sui-rust-operator |
version | 0.1.10 |
source | src |
created_at | 2023-07-20 01:43:26.438534 |
updated_at | 2024-04-24 06:21:37.120551 |
description | sui operator implement with rust |
homepage | https://github.com/v1xingyue/sui-rust-operator |
repository | https://github.com/v1xingyue/sui-rust-operator.git |
max_upload_size | |
id | 920872 |
size | 147,722 |
cargo install --git https://github.com/v1xingyue/sui-rust-operator.git --branch main --bin cargo-sui
sui 官方提供的sdk https://docs.sui.io/testnet/build/rust-sdk 过于臃肿,使用不太方便。
let store = Keystore::default();
let account = store.load_account(0).unwrap();
let new_account: SuiAccount = SuiAccount::new_account();
println!("Account: {} , seed : {} ", new_account, new_account.dump_hex_seed());
2.network 网络设置
let network = network::default();
println!("network : {}", network);
println!("gateway : {}", network.get_gateway());
println!("faucet_url : {}", network.faucet_url());
3.获取交互client
let myclient = client::debug_client(network);
4.读取操作
match myclient.get_object_id(&object_id).await {
Ok(object) => {
println!(
"object detail : {}",
serde_json::to_string_pretty(&object).unwrap()
)
}
Err(err) => {
println!("get object error : {}", err)
}
}
match myclient.get_owned_objects(account.to_address(), query, None, None)
.await
{
Err(err) => {
println!("err :{}", err)
}
Ok(result) => {
println!("data found : {}", result.result.data.len());
}
}
match myclient.get_all_balances(account.to_address()).await {
Err(err) => {
println!("err :{}", err)
}
Ok(result) => {
for balance in result.result {
println!(" {} => {}", balance.coin_type, balance.total_balance)
}
}
}
5.sui 链写操作
通过unsafe rpc 发送数据构建tx_bytes. account 使用对应的私钥,对数据完成签名,再次发送。
构建完成交易后,通过 account.sign_unsafe_transaciton 完成签名。最后使用 send_payload_effect 发送交易。
match myclient
.unsafe_move_call(
&account.to_address(),
&"0x988fb71f38bb0323eeb5014c7a00e5988b047c09f39d58f157fc67d43ddfc091",
&"hello_world",
"mint",
vec![],
vec![],
&"0x6abb224a86b8e571f221ea6bf6a5028923b29b13201a3c29f6fdaaaa3b4cbb97",
3000_000,
)
.await
{
Err(err) => {
println!("{}", err)
}
Ok(data) => {
let signed_payload = account.sign_unsafe_transaciton(data.result);
let effet = myclient.send_payload_effect(&signed_payload).await.unwrap();
println!("reuslt : {}", serde_json::to_string_pretty(&effet).unwrap());
println!(
"transaction link : {}",
myclient
.network
.transaction_link(&effet.result.digest.to_string())
)
}
}
需要使用sui 准备好编译完成的bytes 文件。
sui move build --dump-bytecode-as-base64 --path . > delopy.json
这种方式,用户无需sui的相关知识,直接通过函数模式触发和sui公链的写入即可。
use sui_rust_operator::{
client,
hook::{HookCaller, Target},
keystore::Keystore,
network,
};
let store: Keystore = Keystore::default();
let account = store.load_account(0).unwrap();
let network = network::from_env();
let client = client::default_client(&network);
let mut hook: HookCaller<'_> = HookCaller::new(
Target::new(
String::from("0x2b79486eaddff4fe262519e409214faefde25bcef88bac4f61a799a3d2e490bc"),
String::from("hello_world"),
String::from("mint"),
),
account,
&client,
);
for _ in 1..=3 {
hook.call(vec![], vec![]).await;
}
playground 提供一个测试模块,已完成move_call 的相关功能