Expand description
Sends blocking transactions.
Sends a signed transaction to the RPC and waits until the transaction is fully complete.
Constructs a signed transaction to be sent to an RPC node.
This code sample doesn’t make any requests to the RPC node. It only shows how to construct the request. It’s been truncated for brevity.
A full example on how to use broadcast_tx_commit
method can be found at contract_change_method
.
§Example
use unc_jsonrpc_client::{methods, JsonRpcClient};
use unc_jsonrpc_primitives::types::{query::QueryResponseKind, transactions::TransactionInfo};
use unc_primitives::types::{AccountId, BlockReference};
use unc_primitives::transaction::{Action, FunctionCallAction, Transaction};
use serde_json::json;
let client = JsonRpcClient::connect("https://archival-rpc.testnet.unc.org");
let signer_account_id = "fido.testnet".parse::<AccountId>()?;
let signer_secret_key = "ed25519:12dhevYshfiRqFSu8DSfxA27pTkmGRv6C5qQWTJYTcBEoB7MSTyidghi5NWXzWqrxCKgxVx97bpXPYQxYN5dieU".parse()?;
let signer = unc_crypto::InMemorySigner::from_secret_key(signer_account_id, signer_secret_key);
let other_account = "rpc_docs.testnet".parse::<AccountId>()?;
let rating = "4.5".parse::<f32>()?;
let transaction = Transaction {
signer_id: signer.account_id.clone(),
public_key: signer.public_key.clone(),
nonce: 904565 + 1,
receiver_id: "nosedive.testnet".parse::<AccountId>()?,
block_hash: "AUDcb2iNUbsmCsmYGfGuKzyXKimiNcCZjBKTVsbZGnoH".parse()?,
actions: vec![Action::FunctionCall(Box::new(FunctionCallAction {
method_name: "rate".to_string(),
args: json!({
"account_id": other_account,
"rating": rating,
})
.to_string()
.into_bytes(),
gas: 100_000_000_000_000, // 100 TeraGas
deposit: 0,
}))],
};
let request = methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest {
signed_transaction: transaction.sign(&signer)
};