Skip to content

Commit

Permalink
Expand get transaction (#699)
Browse files Browse the repository at this point in the history
* add SDK examples and explanation to getTransaction

* update code to use <CodeExample>

* use single print in go example

* add install snippets to top of code samples

* fix merge issues

* replace go sdk with Java
  • Loading branch information
Myestery authored Jun 20, 2024
1 parent 7cfd034 commit 224afb1
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions docs/data/rpc/api-reference/methods/getTransaction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

<RpcMethod method="getTransaction" platform="soroban" />

### 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.

<div>
<CodeExample>

```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();
}
}
}
```

</CodeExample>
</div>

0 comments on commit 224afb1

Please sign in to comment.