Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand get transaction #699

Merged
merged 7 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading