Transaction

Transaction creation, signing, and submission.

Transaction handling module for the Saline SDK.

This module provides functions for creating, signing, and encoding transactions for submission to the Saline network.

saline_sdk.transaction.tx.encodeSignedTx(signed)[source]

Encode a signed transaction for network submission.

Parameters:

signed (Signed) – Signed transaction object

Return type:

str

Returns:

Base64 encoded transaction string

saline_sdk.transaction.tx.prepareSimpleTx(signer, tx)[source]

Prepare a simple transaction by signing it with a generated nonce.

This is a convenience function that generates a nonce, signs the transaction, and encodes it in a single step.

Parameters:
Return type:

str

Returns:

Base64 encoded transaction ready for submission

saline_sdk.transaction.tx.print_tx_errors(result, label='Transaction')[source]

Print error details from a Tendermint transaction result.

This function checks the ‘check_tx’ and ‘deliver_tx’ phases of a transaction result. If either phase has a non-zero ‘code’, it prints the phase, error code, and attempts to decode the ‘data’ field from Base64 to provide a human-readable error message.

Parameters:
  • result (dict) – The transaction result dictionary containing ‘check_tx’ and ‘deliver_tx’ entries.

  • label (str) – A label to identify the transaction in the output. Defaults to “Transaction”.

Returns:

None

saline_sdk.transaction.tx.sign(account, nonce, tx)[source]

Sign a transaction with the given account and nonce.

Parameters:
Return type:

Signed

Returns:

Signed transaction object

Raises:

AttributeError – If the account does not support signing

saline_sdk.transaction.tx.tx_is_accepted(result)[source]

Determine if a Tendermint transaction was accepted.

A transaction is considered accepted if both ‘check_tx’ and ‘deliver_tx’ phases have a ‘code’ of 0, indicating success.

check_tx -> pre-flight - transaction is rejectd deliver_tx -> state changed - Transaction is recorded with failure status

Parameters:

result (dict) – The transaction result dictionary containing ‘check_tx’ and ‘deliver_tx’ entries.

Returns:

True if both phases succeeded; False otherwise.

Return type:

bool

Instructions

Transaction instructions module for the Saline SDK.

This module provides helper functions for creating various transaction instructions that can be used when building transactions for the Saline network.

saline_sdk.transaction.instructions.set_intent(signer_pk, condition_type='ConditionTag_Signature')[source]

Create an intent mask entry for authorizations.

Parameters:
  • signer_pk (str) – Signer public key

  • condition_type (str) – Condition tag type, defaults to signature-based authorization

Return type:

List

Returns:

Intent mask entry for use in transactions

Example

>>> set_intent("signer_public_key")
saline_sdk.transaction.instructions.swap(sender, recipient, give_token, give_amount, take_token, take_amount)[source]

Create a pair of instructions for a token swap.

Parameters:
  • sender (str) – Sender’s public key

  • recipient (str) – Recipient’s public key

  • give_token (str) – Token to give (e.g., “USDC”)

  • give_amount (Union[int, float]) – Amount to give

  • take_token (str) – Token to take (e.g., “BTC”)

  • take_amount (Union[int, float]) – Amount to take

Return type:

List[TransferFunds]

Returns:

List of two transfer instructions that make up the swap

Example

>>> swap("alice_pk", "bob_pk", "USDC", 100, "BTC", 0.001)
saline_sdk.transaction.instructions.transfer(sender, recipient, token, amount)[source]

Create a transfer instruction for sending tokens.

Parameters:
  • sender (str) – Sender’s public key

  • recipient (str) – Recipient’s public key

  • token (str) – Token identifier (e.g., “USDC”, “BTC”, “ETH”)

  • amount (Union[int, float]) – Amount to transfer (as integer for atomic units or float for decimal representation)

Return type:

TransferFunds

Returns:

TransferFunds instruction

Example

>>> transfer("sender_public_key", "recipient_public_key", "USDC", 100)

Serialization

Transaction encoding for Saline SDK.

This module handles transaction serialization for both network transmission and signature generation, specifically designed to match Saline’s implementation’s expectations.

saline_sdk.transaction.serialisation.decode_base64(data)[source]

Decode base64 string to binary data.

Parameters:

data (str) – Base64 encoded string

Return type:

bytes

Returns:

Decoded binary data

Raises:

ValueError – If input is not valid base64

saline_sdk.transaction.serialisation.decode_network_tx(data)[source]

Decode a transaction received from the network.

Parameters:

data (bytes) – The encoded transaction bytes

Return type:

Dict[str, Any]

Returns:

Decoded transaction dictionary

Raises:

ValueError – If data is invalid

saline_sdk.transaction.serialisation.encode_base64(data)[source]

Encode binary data as base64 string.

Parameters:

data (bytes) – Binary data to encode

Return type:

str

Returns:

Base64 encoded string

saline_sdk.transaction.serialisation.serialize_for_network(tx)[source]

Serialize transaction for network submission.

Saline requires a hexadecimal encoding with fields in a specific order: 1. Sort all nested dictionaries for deterministic output 2. Convert to JSON with field ordering preserved 3. Encode as hex (base16)

Parameters:

tx (dict) – Transaction dictionary

Return type:

bytes

Returns:

Hex-encoded transaction bytes

Transaction Class

Transaction Operations

saline_sdk.transaction.tx.prepareSimpleTx(signer, tx)[source]

Prepare a simple transaction by signing it with a generated nonce.

This is a convenience function that generates a nonce, signs the transaction, and encodes it in a single step.

Parameters:
Return type:

str

Returns:

Base64 encoded transaction ready for submission

saline_sdk.transaction.tx.encodeSignedTx(signed)[source]

Encode a signed transaction for network submission.

Parameters:

signed (Signed) – Signed transaction object

Return type:

str

Returns:

Base64 encoded transaction string

saline_sdk.transaction.tx.sign(account, nonce, tx)[source]

Sign a transaction with the given account and nonce.

Parameters:
Return type:

Signed

Returns:

Signed transaction object

Raises:

AttributeError – If the account does not support signing

Transaction Instructions

saline_sdk.transaction.instructions.transfer(sender, recipient, token, amount)[source]

Create a transfer instruction for sending tokens.

Parameters:
  • sender (str) – Sender’s public key

  • recipient (str) – Recipient’s public key

  • token (str) – Token identifier (e.g., “USDC”, “BTC”, “ETH”)

  • amount (Union[int, float]) – Amount to transfer (as integer for atomic units or float for decimal representation)

Return type:

TransferFunds

Returns:

TransferFunds instruction

Example

>>> transfer("sender_public_key", "recipient_public_key", "USDC", 100)
saline_sdk.transaction.instructions.swap(sender, recipient, give_token, give_amount, take_token, take_amount)[source]

Create a pair of instructions for a token swap.

Parameters:
  • sender (str) – Sender’s public key

  • recipient (str) – Recipient’s public key

  • give_token (str) – Token to give (e.g., “USDC”)

  • give_amount (Union[int, float]) – Amount to give

  • take_token (str) – Token to take (e.g., “BTC”)

  • take_amount (Union[int, float]) – Amount to take

Return type:

List[TransferFunds]

Returns:

List of two transfer instructions that make up the swap

Example

>>> swap("alice_pk", "bob_pk", "USDC", 100, "BTC", 0.001)
saline_sdk.transaction.instructions.set_intent(signer_pk, condition_type='ConditionTag_Signature')[source]

Create an intent mask entry for authorizations.

Parameters:
  • signer_pk (str) – Signer public key

  • condition_type (str) – Condition tag type, defaults to signature-based authorization

Return type:

List

Returns:

Intent mask entry for use in transactions

Example

>>> set_intent("signer_public_key")

Transaction Serialization

Transaction encoding for Saline SDK.

This module handles transaction serialization for both network transmission and signature generation, specifically designed to match Saline’s implementation’s expectations.

saline_sdk.transaction.serialisation.decode_base64(data)[source]

Decode base64 string to binary data.

Parameters:

data (str) – Base64 encoded string

Return type:

bytes

Returns:

Decoded binary data

Raises:

ValueError – If input is not valid base64

saline_sdk.transaction.serialisation.decode_network_tx(data)[source]

Decode a transaction received from the network.

Parameters:

data (bytes) – The encoded transaction bytes

Return type:

Dict[str, Any]

Returns:

Decoded transaction dictionary

Raises:

ValueError – If data is invalid

saline_sdk.transaction.serialisation.encode_base64(data)[source]

Encode binary data as base64 string.

Parameters:

data (bytes) – Binary data to encode

Return type:

str

Returns:

Base64 encoded string

saline_sdk.transaction.serialisation.serialize_for_network(tx)[source]

Serialize transaction for network submission.

Saline requires a hexadecimal encoding with fields in a specific order: 1. Sort all nested dictionaries for deterministic output 2. Convert to JSON with field ordering preserved 3. Encode as hex (base16)

Parameters:

tx (dict) – Transaction dictionary

Return type:

bytes

Returns:

Hex-encoded transaction bytes