pub struct Transaction;Expand description
Transaction related functionality.
This struct provides ability to interact with transactions.
Implementations§
Source§impl Transaction
impl Transaction
Sourcepub const fn construct(
signer_id: AccountId,
receiver_id: AccountId,
) -> ConstructTransaction
pub const fn construct( signer_id: AccountId, receiver_id: AccountId, ) -> ConstructTransaction
Constructs a new transaction builder with the given signer and receiver IDs. This pattern is useful for batching actions into a single transaction.
This is the low level interface for constructing transactions. It is designed to be used in scenarios where more control over the transaction process is required.
§Example
This example constructs a transaction with a two transfer actions.
use near_api::{*, types::{transaction::actions::{Action, TransferAction}, json::U128}};
let signer = Signer::from_ledger()?;
let transaction_result = Transaction::construct(
"sender.near".parse()?,
"receiver.near".parse()?
)
.add_action(Action::Transfer(
TransferAction {
deposit: NearToken::from_near(1),
},
))
.add_action(Action::Transfer(
TransferAction {
deposit: NearToken::from_near(1),
},
))
.with_signer(signer)
.send_to_mainnet()
.await?;Sourcepub fn use_transaction(
unsigned_tx: PrepopulateTransaction,
signer: Arc<Signer>,
) -> ExecuteSignedTransaction
pub fn use_transaction( unsigned_tx: PrepopulateTransaction, signer: Arc<Signer>, ) -> ExecuteSignedTransaction
Signs a transaction with the given signer.
This provides ability to sign custom constructed pre-populated transactions.
§Examples
use near_api::*;
let signer = Signer::from_ledger()?;
let transaction_result = Transaction::use_transaction(
unsigned_tx,
signer
)
.send_to_mainnet()
.await?;Sourcepub fn status(
sender_account_id: AccountId,
tx_hash: CryptoHash,
) -> RequestBuilder<TransactionStatusHandler>
pub fn status( sender_account_id: AccountId, tx_hash: CryptoHash, ) -> RequestBuilder<TransactionStatusHandler>
Sets up a query to fetch the current status of a transaction by its hash and sender account ID.
Waits until the transaction has been optimistically executed (TxExecutionStatus::ExecutedOptimistic),
ensuring that outcome fields (gas usage, logs, status) are populated.
If you need to wait until the transaction reaches a different stage
(e.g., TxExecutionStatus::Final or TxExecutionStatus::None),
use Transaction::status_with_options instead.
The returned result is an ExecutionFinalResult
which provides details about gas usage, logs, and the execution status.
§Example
use near_api::*;
let tx_hash: CryptoHash = "EaNakSaXUTjbPsUJbuDdbuq3e6Ynmjo8zYUgDVqt1iTn".parse()?;
let sender: AccountId = "sender.near".parse()?;
let result = Transaction::status(sender, tx_hash)
.fetch_from_mainnet()
.await?;
println!("Transaction success: {}", result.is_success());Sourcepub fn status_with_options(
sender_account_id: AccountId,
tx_hash: CryptoHash,
wait_until: TxExecutionStatus,
) -> RequestBuilder<TransactionStatusHandler>
pub fn status_with_options( sender_account_id: AccountId, tx_hash: CryptoHash, wait_until: TxExecutionStatus, ) -> RequestBuilder<TransactionStatusHandler>
Sets up a query to fetch the status of a transaction, waiting until it reaches the specified execution stage.
Use TxExecutionStatus::None to return immediately with whatever state is available,
or TxExecutionStatus::Final to wait until the transaction is fully finalized.
§Example
use near_api::{*, types::TxExecutionStatus};
let tx_hash: CryptoHash = "EaNakSaXUTjbPsUJbuDdbuq3e6Ynmjo8zYUgDVqt1iTn".parse()?;
let sender: AccountId = "sender.near".parse()?;
let result = Transaction::status_with_options(
sender,
tx_hash,
TxExecutionStatus::Final,
)
.fetch_from_mainnet()
.await?;Sourcepub fn receipt(receipt_id: CryptoHash) -> RequestBuilder<ReceiptHandler>
pub fn receipt(receipt_id: CryptoHash) -> RequestBuilder<ReceiptHandler>
Sets up a query to fetch a receipt by its ID.
This uses the EXPERIMENTAL_receipt RPC method to retrieve the details of a specific receipt.
§Example
use near_api::*;
let receipt_id: CryptoHash = "EaNakSaXUTjbPsUJbuDdbuq3e6Ynmjo8zYUgDVqt1iTn".parse()?;
let receipt = Transaction::receipt(receipt_id)
.fetch_from_mainnet()
.await?;
println!("Receipt receiver: {:?}", receipt.receiver_id);Sourcepub fn proof(
sender_id: AccountId,
transaction_hash: CryptoHash,
light_client_head: CryptoHash,
) -> RequestBuilder<TransactionProofRpc>
pub fn proof( sender_id: AccountId, transaction_hash: CryptoHash, light_client_head: CryptoHash, ) -> RequestBuilder<TransactionProofRpc>
Sets up a query to fetch the light client execution proof for a transaction.
This is used to verify a transaction’s execution against a light client block header.
The light_client_head parameter specifies the block hash of the light client’s latest known head.
§Example
use near_api::*;
let tx_hash: CryptoHash = "EaNakSaXUTjbPsUJbuDdbuq3e6Ynmjo8zYUgDVqt1iTn".parse()?;
let sender: AccountId = "sender.near".parse()?;
let head_hash: CryptoHash = "3i1SypXzBRhLMvpHmNJXpg18FgVW6jNFrFcUqBF5Wmit".parse()?;
let proof = Transaction::proof(sender, tx_hash, head_hash)
.fetch_from_mainnet()
.await?;
println!("Proof block header: {:?}", proof.block_header_lite);Trait Implementations§
Source§impl Clone for Transaction
impl Clone for Transaction
Source§fn clone(&self) -> Transaction
fn clone(&self) -> Transaction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more