pub struct Transaction(pub Transaction);
Expand description

An atomically-commited sequence of instructions.

While :class:~solders.instruction.Instruction\s are the basic unit of computation in Solana, they are submitted by clients in :class:~solders.transaction.Transaction\s containing one or more instructions, and signed by one or more signers.

See the Rust module documentation <https://docs.rs/solana-sdk/latest/solana_sdk/transaction/index.html>_ for more details about transactions.

Some constructors accept an optional payer, the account responsible for paying the cost of executing a transaction. In most cases, callers should specify the payer explicitly in these constructors. In some cases though, the caller is not required to specify the payer, but is still allowed to: in the :class:~solders.message.Message object, the first account is always the fee-payer, so if the caller has knowledge that the first account of the constructed transaction’s Message is both a signer and the expected fee-payer, then redundantly specifying the fee-payer is not strictly required.

The main Transaction() constructor creates a fully-signed transaction from a Message.

Args: from_keypairs (Sequence[Keypair | Presigner]): The keypairs that are to sign the transaction. message (Message): The message to sign. recent_blockhash (Hash): The id of a recent ledger entry.

Example: >>> from solders.message import Message >>> from solders.keypair import Keypair >>> from solders.instruction import Instruction >>> from solders.hash import Hash >>> from solders.transaction import Transaction >>> from solders.pubkey import Pubkey >>> program_id = Pubkey.default() >>> arbitrary_instruction_data = bytes([1]) >>> accounts = [] >>> instruction = Instruction(program_id, arbitrary_instruction_data, accounts) >>> payer = Keypair() >>> message = Message([instruction], payer.pubkey()) >>> blockhash = Hash.default() # replace with a real blockhash >>> tx = Transaction([payer], message, blockhash)

Tuple Fields§

§0: Transaction

Implementations§

source§

impl Transaction

source

pub fn new( from_keypairs: Vec<Signer>, message: &Message, recent_blockhash: SolderHash ) -> Self

source

pub fn signatures(&self) -> Vec<Signature>

listSignature: A set of signatures of a serialized :class:~solders.message.Message, signed by the first keys of the message’s :attr:~solders.message.Message.account_keys, where the number of signatures is equal to num_required_signatures of the Message’s :class:~solders.message.MessageHeader.

source

pub fn message(&self) -> Message

Message: The message to sign.

source

pub fn new_unsigned(message: Message) -> Self

Create an unsigned transaction from a :class:~solders.message.Message.

Args: message (Message): The transaction’s message.

Returns: Transaction: The unsigned transaction.

Example: >>> from typing import List >>> from solders.message import Message >>> from solders.keypair import Keypair >>> from solders.pubkey import Pubkey >>> from solders.instruction import Instruction, AccountMeta >>> from solders.hash import Hash >>> from solders.transaction import Transaction >>> program_id = Pubkey.default() >>> blockhash = Hash.default() # replace with a real blockhash >>> arbitrary_instruction_data = bytes([1]) >>> accounts: List[AccountMeta] = [] >>> instruction = Instruction(program_id, arbitrary_instruction_data, accounts) >>> payer = Keypair() >>> message = Message.new_with_blockhash([instruction], payer.pubkey(), blockhash) >>> tx = Transaction.new_unsigned(message) >>> tx.sign([payer], tx.message.recent_blockhash)

source

pub fn new_with_payer( instructions: Vec<Instruction>, payer: Option<&Pubkey> ) -> Self

Create an unsigned transaction from a list of :class:~solders.instruction.Instruction\s.

Args: instructions (SequenceInstruction): The instructions to include in the transaction message. payer (OptionalPubkey, optional): The transaction fee payer. Defaults to None.

Returns: Transaction: The unsigned transaction.

Example: >>> from solders.keypair import Keypair >>> from solders.instruction import Instruction >>> from solders.transaction import Transaction >>> from solders.pubkey import Pubkey >>> program_id = Pubkey.default() >>> arbitrary_instruction_data = bytes([1]) >>> accounts = [] >>> instruction = Instruction(program_id, arbitrary_instruction_data, accounts) >>> payer = Keypair() >>> tx = Transaction.new_with_payer([instruction], payer.pubkey())

source

pub fn new_signed_with_payer( instructions: Vec<Instruction>, payer: Option<Pubkey>, signing_keypairs: Vec<Signer>, recent_blockhash: SolderHash ) -> Self

Create a fully-signed transaction from a list of :class:~solders.instruction.Instruction\s.

Args: instructions (SequenceInstruction): The instructions to include in the transaction message. payer (OptionalPubkey, optional): The transaction fee payer. signing_keypairs (Sequence[Keypair | Presigner]): The keypairs that will sign the transaction. recent_blockhash (Hash): The id of a recent ledger entry.

Returns: Transaction: The signed transaction.

Example: >>> from solders.keypair import Keypair >>> from solders.instruction import Instruction >>> from solders.transaction import Transaction >>> from solders.pubkey import Pubkey >>> program_id = Pubkey.default() >>> arbitrary_instruction_data = bytes([1]) >>> accounts = [] >>> instruction = Instruction(program_id, arbitrary_instruction_data, accounts) >>> payer = Keypair() >>> blockhash = Hash.default() # replace with a real blockhash >>> tx = Transaction.new_signed_with_payer([instruction], payer.pubkey(), [payer], blockhash);

source

pub fn new_with_compiled_instructions( from_keypairs: Vec<Signer>, keys: Vec<Pubkey>, recent_blockhash: SolderHash, program_ids: Vec<Pubkey>, instructions: Vec<CompiledInstruction> ) -> Self

Create a fully-signed transaction from pre-compiled instructions.

Args: from_keypairs (Sequence[Keypair | Presigner]): The keys used to sign the transaction. keys (SequencePubkey): The keys for the transaction. These are the program state instances or lamport recipient keys. recent_blockhash (Hash): The PoH hash. program_ids (SequencePubkey): The keys that identify programs used in the instruction vector. instructions (SequenceInstruction): Instructions that will be executed atomically.

Returns: Transaction: The signed transaction.

source

pub fn populate(message: Message, signatures: Vec<Signature>) -> Self

Create a fully-signed transaction from a message and its signatures.

Args: message (Message): The transaction message. signatures (SequenceSignature): The message’s signatures.

Returns: Message: The signed transaction.

Example:

>>> from solders.keypair import Keypair
>>> from solders.instruction import Instruction
>>> from solders.transaction import Transaction
>>> from solders.pubkey import Pubkey
>>> program_id = Pubkey.default()
>>> arbitrary_instruction_data = bytes([1])
>>> accounts = []
>>> instruction = Instruction(program_id, arbitrary_instruction_data, accounts)
>>> payer = Keypair()
>>> blockhash = Hash.default()  # replace with a real blockhash
>>> tx = Transaction.new_signed_with_payer([instruction], payer.pubkey(), [payer], blockhash);
>>> assert tx == Transaction.populate(tx.message, tx.signatures)
source

pub fn data(&self, instruction_index: usize) -> &[u8]

Get the data for an instruction at the given index.

Args: instruction_index (int): index into the instructions vector of the transaction’s message.

Returns: bytes: The instruction data.

source

pub fn key( &self, instruction_index: usize, accounts_index: usize ) -> Option<Pubkey>

Get the :class:~solders.pubkey.Pubkey of an account required by one of the instructions in the transaction.

Returns None if instruction_index is greater than or equal to the number of instructions in the transaction; or if accounts_index is greater than or equal to the number of accounts in the instruction.

Args: instruction_index (int): index into the instructions vector of the transaction’s message. account_index (int): index into the acounts list of the message’s compiled_instructions.

Returns: OptionalPubkey: The account key.

source

pub fn signer_key( &self, instruction_index: usize, accounts_index: usize ) -> Option<Pubkey>

Get the :class:~solders.pubkey.Pubkey of a signing account required by one of the instructions in the transaction.

The transaction does not need to be signed for this function to return a signing account’s pubkey.

Returns None if the indexed account is not required to sign the transaction. Returns None if the [signatures] field does not contain enough elements to hold a signature for the indexed account (this should only be possible if Transaction has been manually constructed).

Returns None if instruction_index is greater than or equal to the number of instructions in the transaction; or if accounts_index is greater than or equal to the number of accounts in the instruction.

Args: instruction_index (int): index into the instructions vector of the transaction’s message. account_index (int): index into the acounts list of the message’s compiled_instructions.

Returns: OptionalPubkey: The account key.

source

pub fn message_data<'a>(&self, py: Python<'a>) -> &'a PyBytes

Return the serialized message data to sign.

Returns: bytes: The serialized message data.

source

pub fn sign( &mut self, keypairs: Vec<Signer>, recent_blockhash: SolderHash ) -> PyResult<()>

Sign the transaction, returning any errors.

This method fully signs a transaction with all required signers, which must be present in the keypairs list. To sign with only some of the required signers, use :meth:Transaction.partial_sign.

If recent_blockhash is different than recorded in the transaction message’s recent_blockhash] field, then the message’s recent_blockhash will be updated to the provided recent_blockhash, and any prior signatures will be cleared.

Errors:

Signing will fail if some required signers are not provided in keypairs; or, if the transaction has previously been partially signed, some of the remaining required signers are not provided in keypairs. In other words, the transaction must be fully signed as a result of calling this function.

Signing will fail for any of the reasons described in the documentation for :meth:Transaction.partial_sign.

Args: keypairs (Sequence[Keypair | Presigner]): The signers for the transaction. recent_blockhash (Hash): The id of a recent ledger entry.

source

pub fn partial_sign( &mut self, keypairs: Vec<Signer>, recent_blockhash: SolderHash ) -> PyResult<()>

Sign the transaction with a subset of required keys, returning any errors.

Unlike :meth:Transaction.sign, this method does not require all keypairs to be provided, allowing a transaction to be signed in multiple steps.

It is permitted to sign a transaction with the same keypair multiple times.

If recent_blockhash is different than recorded in the transaction message’s recent_blockhash field, then the message’s recent_blockhash will be updated to the provided recent_blockhash, and any prior signatures will be cleared.

Errors:

Signing will fail if

  • The transaction’s :class:~solders.message.Message is malformed such that the number of required signatures recorded in its header (num_required_signatures) is greater than the length of its account keys (account_keys).
  • Any of the provided signers in keypairs is not a required signer of the message.
  • Any of the signers is a :class:~solders.presigner.Presigner, and its provided signature is incorrect.

Args: keypairs (Sequence[Keypair | Presigner]): The signers for the transaction. recent_blockhash (Hash): The id of a recent ledger entry.

source

pub fn verify(&self) -> PyResult<()>

Verifies that all signers have signed the message.

Raises: TransactionError: if the check fails.

source

pub fn verify_and_hash_message(&self) -> PyResult<SolderHash>

Verify the transaction and hash its message.

Returns: Hash: The blake3 hash of the message.

Raises: TransactionError: if the check fails.

source

pub fn verify_with_results(&self) -> Vec<bool>

Verifies that all signers have signed the message.

Returns: listbool: a list with the length of required signatures, where each element is either True if that signer has signed, or False if not.

source

pub fn get_signing_keypair_positions( &self, pubkeys: Vec<Pubkey> ) -> PyResult<Vec<Option<usize>>>

Get the positions of the pubkeys in account_keys associated with signing keypairs.

Args: pubkeys (SequencePubkey): The pubkeys to find.

Returns:
    list[Optional[int]]: The pubkey positions.
source

pub fn replace_signatures( &mut self, signers: Vec<(Pubkey, Signature)> ) -> PyResult<()>

Replace all the signatures and pubkeys.

Args: signers (Sequence[Tuple[Pubkey, Signature]]): The replacement pubkeys and signatures.

source

pub fn is_signed(&self) -> bool

Check if the transaction has been signed.

Returns: bool: True if the transaction has been signed.

source

pub fn uses_durable_nonce(&self) -> Option<CompiledInstruction>

See https://docs.rs/solana-sdk/latest/solana_sdk/transaction/fn.uses_durable_nonce.html

source

pub fn sanitize(&self) -> PyResult<()>

Sanity checks the Transaction properties.

source

pub fn new_default() -> Self

Return a new default transaction.

Returns: Transaction: The default transaction.

source

pub fn from_bytes(data: &[u8]) -> PyResult<Self>

Deserialize a serialized Transaction object.

Args: data (bytes): the serialized Transaction.

Returns: Transaction: the deserialized Transaction.

Example: >>> from solders.transaction import Transaction >>> tx = Transaction.default() >>> assert Transaction.from_bytes(bytes(tx)) == tx

source

pub fn get_nonce_pubkey_from_instruction( &self, ix: &CompiledInstruction ) -> Option<Pubkey>

Deprecated in the Solana Rust SDK, expose here only for testing.

source

pub fn __richcmp__(&self, other: &Self, op: CompareOp) -> PyResult<bool>

source

pub fn __bytes__<'a>(&self, py: Python<'a>) -> &'a PyBytes

source

pub fn __str__(&self) -> String

source

pub fn __repr__(&self) -> String

source

pub fn __reduce__(&self) -> PyResult<(PyObject, PyObject)>

source

pub fn to_json(&self) -> String

Convert to a JSON string.

source

pub fn from_json(raw: &str) -> PyResult<Self>

Build from a JSON string.

Trait Implementations§

source§

impl AsRef<Transaction> for Transaction

source§

fn as_ref(&self) -> &TransactionOriginal

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Transaction

source§

fn clone(&self) -> Transaction

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl CommonMethods<'_> for Transaction

source§

fn py_to_json(&self) -> String

source§

fn py_from_json(raw: &'a str) -> Result<Self, PyErr>

source§

impl CommonMethodsCore for Transaction

source§

fn pybytes<'b>(&self, py: Python<'b>) -> &'b PyBytes

source§

fn pystr(&self) -> String

source§

fn pyrepr(&self) -> String

source§

fn py_from_bytes(raw: &[u8]) -> Result<Self, PyErr>

source§

fn pyreduce(&self) -> Result<(Py<PyAny>, Py<PyAny>), PyErr>

source§

impl Debug for Transaction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Transaction

source§

fn default() -> Transaction

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Transaction

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Transaction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Transaction> for Transaction

source§

fn from(original: TransactionOriginal) -> Transaction

Converts to this type from the input type.
source§

impl From<Transaction> for Transaction

source§

fn from(original: Transaction) -> Self

Converts to this type from the input type.
source§

impl From<Transaction> for VersionedTransaction

source§

fn from(t: Transaction) -> Self

Converts to this type from the input type.
source§

impl IntoPy<Py<PyAny>> for Transaction

source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
source§

impl PartialEq for Transaction

source§

fn eq(&self, other: &Transaction) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PyBytesBincode for Transaction

source§

fn pybytes_bincode<'a>(&self, py: Python<'a>) -> &'a PyBytes

source§

impl PyBytesGeneral for Transaction

source§

fn pybytes_general<'a>(&self, py: Python<'a>) -> &'a PyBytes

source§

impl PyClass for Transaction

§

type Frozen = False

Whether the pyclass is frozen. Read more
source§

impl PyClassImpl for Transaction

source§

const IS_BASETYPE: bool = true

#[pyclass(subclass)]
source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
§

type Layout = PyCell<Transaction>

Layout
§

type BaseType = PyAny

Base class
§

type ThreadChecker = ThreadCheckerStub<Transaction>

This handles following two situations: Read more
§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
source§

fn items_iter() -> PyClassItemsIter

source§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

source§

fn dict_offset() -> Option<isize>

source§

fn weaklist_offset() -> Option<isize>

source§

impl PyClassNewTextSignature<Transaction> for PyClassImplCollector<Transaction>

source§

fn new_text_signature(self) -> Option<&'static str>

source§

impl PyFromBytesBincode<'_> for Transaction

source§

fn py_from_bytes_bincode(raw: &'b [u8]) -> Result<Self, PyErr>

source§

impl PyFromBytesGeneral for Transaction

source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a Transaction

§

type Holder = Option<PyRef<'py, Transaction>>

source§

fn extract(obj: &'py PyAny, holder: &'a mut Self::Holder) -> PyResult<Self>

source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut Transaction

§

type Holder = Option<PyRefMut<'py, Transaction>>

source§

fn extract(obj: &'py PyAny, holder: &'a mut Self::Holder) -> PyResult<Self>

source§

impl PyMethods<Transaction> for PyClassImplCollector<Transaction>

source§

fn py_methods(self) -> &'static PyClassItems

source§

impl PyTypeInfo for Transaction

§

type AsRefTarget = PyCell<Transaction>

Utility type to make Py::as_ref work.
source§

const NAME: &'static str = "Transaction"

Class name.
source§

const MODULE: Option<&'static str> = _

Module name, if any.
source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
source§

fn type_object(py: Python<'_>) -> &PyType

Returns the safe abstraction over the type object.
source§

fn is_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type or a subclass of this type.
source§

fn is_exact_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type.
source§

impl RichcmpEqualityOnly for Transaction

source§

fn richcmp(&self, other: &Self, op: CompareOp) -> Result<bool, PyErr>

source§

impl Serialize for Transaction

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Transaction

source§

impl StructuralEq for Transaction

source§

impl StructuralPartialEq for Transaction

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> AbiEnumVisitor for T
where T: Serialize + AbiExample + ?Sized,

§

default fn visit_for_abi( &self, digester: &mut AbiDigester ) -> Result<AbiDigester, DigestError>

§

impl<T> AbiEnumVisitor for T
where T: Serialize + ?Sized,

§

default fn visit_for_abi( &self, _digester: &mut AbiDigester ) -> Result<AbiDigester, DigestError>

§

impl<T> AbiExample for T

§

default fn example() -> T

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'a, T> FromPyObject<'a> for T
where T: PyClass + Clone,

source§

fn extract(obj: &'a PyAny) -> Result<T, PyErr>

Extracts Self from the source PyObject.
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> OkWrap<T> for T
where T: IntoPy<Py<PyAny>>,

§

type Error = PyErr

source§

fn wrap(self, py: Python<'_>) -> Result<Py<PyAny>, PyErr>

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Ungil for T
where T: Send,