当通过 ContractCallHandler
进行合约调用或通过 ScriptCallHandler
进行脚本调用时,Rust SDK 在后台使用交易构建器。您可以获取此构建器并在将其提交到网络之前自定义它。交易成功执行后,您可以使用相应的 ContractCallHandler
或 ScriptCallHandler
生成调用响应 。调用响应可用于解码返回值和日志。以下是合约调用和脚本调用的示例。
let call_handler = contract_instance.methods().initialize_counter(counter);
let mut tb = call_handler.transaction_builder().await?;
// customize the builder...
wallet.adjust_for_fee(&mut tb, 0).await?;
tb.add_signer(wallet.clone())?;
let tx = tb.build(provider).await?;
let tx_id = provider.send_transaction(tx).await?;
let tx_status = provider.tx_status(&tx_id).await?;
let response = call_handler.get_response_from(tx_status)?;
assert_eq!(counter, response.value);
let script_call_handler = script_instance.main(1, 2);
let mut tb = script_call_handler.transaction_builder().await?;
// customize the builder...
wallet.adjust_for_fee(&mut tb, 0).await?;
tb.add_signer(wallet.clone())?;
let tx = tb.build(provider).await?;
let tx_id = provider.send_transaction(tx).await?;
let tx_status = provider.tx_status(&tx_id).await?;
let response = script_call_handler.get_response_from(tx_status)?;
assert_eq!(response.value, "hello");