Skip to main content
Loading method details…

SDK Guide

The example above is sending a transaction using RPC methods directly. If you are using the Stellar SDK to build applications, you can use the native functions to get the same information.

# pip install --upgrade stellar-sdk
from stellar_sdk import SorobanServer, soroban_rpc, Keypair, Network, TransactionBuilder, scval

def send_transaction() -> soroban_rpc.SendTransactionResponse:
server = SorobanServer(server_url='https://soroban-testnet.stellar.org', client=None)

root_keypair = Keypair.from_secret(
"SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
)
root_account = server.load_account(root_keypair.public_key)
# native token contract (XLM)
contract_id = "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC"
transaction = (
TransactionBuilder(
source_account=root_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=100,
)
# Transfer 1 native token to GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H
# https://developers.stellar.org/docs/tokens/token-interface
.append_invoke_contract_function_op(contract_id, "transfer", [
scval.to_address(root_keypair.public_key), # from
scval.to_address("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"), # to
scval.to_int128(1 * 10 ** 7) # amount, 1 XLM, decimal places are 7
])
.set_timeout(30)
.build()
)

transaction = server.prepare_transaction(transaction)
transaction.sign(root_keypair)
return server.send_transaction(transaction)


response = send_transaction()

print("status", response.status)
print("hash:", response.hash)
print("status:", response.status)
print("errorResultXdr:", response.error_result_xdr)

Using the Lab

The sendTransaction method is used to submit a real transaction to the Stellar network, making it the only way to execute on-chain changes through RPC.

Unlike Horizon, this method does not wait for confirmation. Instead, it validates and enqueues the transaction. To track its final outcome, clients should follow up with a call to getTransaction.

This method supports all Stellar transactions, including but not limited to smart contract invocations.

👉 Send (Submit) a Transaction on the Lab

Lab Send Transaction RPC