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

add SDK examples and explanation to getTransaction #698

Closed
wants to merge 4 commits into from
Closed
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
71 changes: 70 additions & 1 deletion network/soroban-rpc/api-reference/methods/getTransaction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,76 @@
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.

<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");
```

```go
// go get github.com/stellar/go/clients/horizonclient

package main

import (
"fmt"
"net/http"

"github.com/stellar/go/clients/horizonclient"
)

func main() {
client := horizonclient.Client{
HorizonURL: "https://horizon-testnet.stellar.org",
HTTP: http.DefaultClient,
}
res, err := client.TransactionDetail("84577409a21a25c60b610667c5a2e9355d65393af20cb96f8ac506d3991b9230")
if err != nil {
fmt.Println(err)
}
fmt.Println(res)
}
```

</CodeExample>

Loading