Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/distributed-lab/tron-sdk
https://github.com/distributed-lab/tron-sdk
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/distributed-lab/tron-sdk
- Owner: distributed-lab
- Created: 2023-08-16T12:42:24.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-06T14:43:50.000Z (about 1 year ago)
- Last Synced: 2024-08-19T11:44:41.175Z (5 months ago)
- Language: Go
- Size: 34.2 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TRON SDK
The **TRON SDK** is a Go client library designed to simplify interaction with the TRON blockchain's API, specifically the **TronGrid** service. TronGrid is a public API service provided by the TRON Foundation that offers various endpoints for querying TRON blockchain data.
## Features
- Retrieve information about blocks, transactions, and contract events.
- Check account balances for native tokens and TRC20 tokens.
- Obtain details about transactions and their results.
- Interact with smart contract functions and retrieve contract owner information.## Installation
To install the **tron-api** SDK, you can use the `go get` command:
```bash
go get -u github.com/distributed-lab/tron-api
```## Usage
```go
package mainimport (
"fmt"
"time""github.com/distributed-lab/tron-sdk/tron_api"
)func main() {
apiKey := "your-api-key"
httpApiURL := "https://api.trongrid.io"
grpcURL := "grpc.trongrid.io:50051"client := tron_api.NewTronClient(httpApiURL, grpcURL, apiKey)
blockNumber, err := client.GetNowBlock()
if err != nil {
fmt.Println("Error:", err)
return
}fmt.Println("Latest Block Number:", blockNumber)
// Perform other operations using the provided methods
// ...
}
```## TronGrid Usage
This SDK interacts with the TRON blockchain through the **TronGrid** service, which offers a range of methods to retrieve blockchain data. Some of the key methods utilized by this SDK include:
- `GetNowBlock()`: Retrieve the latest block number.
- `GetTransactionInfoByBlockNum(block int64)`: Get transaction information by block number.
- `GetTransactionResultById(id string)`: Fetch the result of a transaction by its ID.
- `GetTxInfo(id string)`: Obtain detailed transaction information by ID.
- `BalanceOf(address address.Address, tokenAddress string)`: Check account balances for native tokens and TRC20 tokens.
- `GetContractOwner(c address.Address)`: Retrieve the owner of a smart contract.For more details on these methods and other available endpoints, refer to the official [TronGrid API documentation](https://developers.tron.network/reference/full-node-api-overview).