From 224afb1378281ae5722a348077a3b58d5e69a0aa Mon Sep 17 00:00:00 2001 From: Chiwetelu Johnpaul Chidera <49923152+Myestery@users.noreply.github.com> Date: Thu, 20 Jun 2024 23:49:20 +0100 Subject: [PATCH] Expand get transaction (#699) * add SDK examples and explanation to getTransaction * update code to use * use single print in go example * add install snippets to top of code samples * fix merge issues * replace go sdk with Java --- .../api-reference/methods/getTransaction.mdx | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/docs/data/rpc/api-reference/methods/getTransaction.mdx b/docs/data/rpc/api-reference/methods/getTransaction.mdx index 8ab2b45c8..2f2269ee6 100644 --- a/docs/data/rpc/api-reference/methods/getTransaction.mdx +++ b/docs/data/rpc/api-reference/methods/getTransaction.mdx @@ -3,6 +3,74 @@ hide_title: true description: Returns transaction details --- +import { CodeExample } from "@site/src/components/CodeExample"; import { RpcMethod } from "@site/src/components/RpcMethod"; + +### SDK Guide + +The example above is querying details of 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. + +
+ + +```python +# pip install --upgrade stellar-sdk +from stellar_sdk import SorobanServer, soroban_rpc + + +def get_transaction(hash: str) -> soroban_rpc.GetTransactionResponse: + server = SorobanServer(server_url='https://soroban-testnet.stellar.org', client=None) + tx = server.get_transaction(hash) + return tx + +tx = get_transaction("6bc97bddc21811c626839baf4ab574f4f9f7ddbebb44d286ae504396d4e752da") + +print("result", tx.status) +``` + +```js +// yarn add @stellar/stellar-sdk +import { Server } from "@stellar/stellar-sdk/rpc"; + +const server = new Server("https://soroban-testnet.stellar.org"); + +// Fetch transaction details +async function getTransactionDetails(hash) { + try { + server.getTransaction(hash).then((tx) => { + console.log({ result: tx }); + }); + } catch (error) { + console.error("Error fetching transaction:", error); + } +} + +getTransactionDetails( + "6bc97bddc21811c626839baf4ab574f4f9f7ddbebb44d286ae504396d4e752da", +); +``` + +```java +// implementation 'network.lightsail:stellar-sdk:0.44.0' + +import org.stellar.sdk.SorobanServer; +import org.stellar.sdk.responses.sorobanrpc.GetTransactionResponse; + +public class GetTransactionExample { + public static void main(String[] args) { + SorobanServer server = new SorobanServer("https://soroban-testnet.stellar.org"); + try { + GetTransactionResponse tx = server.getTransaction("6bc97bddc21811c626839baf4ab574f4f9f7ddbebb44d286ae504396d4e752da"); + System.out.println("result: " + tx); + } catch (Exception e) { + System.err.println("An error has occurred:"); + e.printStackTrace(); + } + } +} +``` + + +