Build a TRON Wallet in Go

GoTRON SDK provides comprehensive wallet management: keystore-based accounts, HD key derivation, and Ledger hardware wallet signing.

Create a New Account

Generate a new TRON account with an encrypted keystore:

package main

import (
    "fmt"
    "log"

    "github.com/fbsobreira/gotron-sdk/pkg/keystore"
)

func main() {
    ks := keystore.NewKeyStore("./keystore")

    account, err := ks.NewAccount("your-secure-passphrase")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("New address: %s\n", account.Address)
}

Import a Private Key

Import an existing TRON private key:

import "crypto/ecdsa"
import "github.com/fbsobreira/gotron-sdk/pkg/keystore"

ks := keystore.NewKeyStore("./keystore")
account, err := ks.ImportECDSA(privateKey, "passphrase")

List Accounts

ks := keystore.NewKeyStore("./keystore")
for _, account := range ks.Accounts() {
    fmt.Printf("Address: %s\n", account.Address)
}

Sign a Transaction

// Build a transaction
tx, err := conn.Transfer(from, to, 1_000_000)
if err != nil {
    log.Fatal(err)
}

// Sign with keystore
ks := keystore.NewKeyStore("./keystore")
account := ks.Accounts()[0]

signedTx, err := ks.SignTx(account, tx.Transaction)
if err != nil {
    log.Fatal(err)
}

// Broadcast
result, err := conn.Broadcast(signedTx)

Ledger Hardware Wallet

GoTRON is the only TRON SDK with native Ledger support:

import "github.com/fbsobreira/gotron-sdk/pkg/ledger"

// Sign with Ledger device
signedTx, err := ledger.SignTx(txBytes)
if err != nil {
    log.Fatal(err)
}

Using tronctl CLI

# Create a new wallet
tronctl keys add my-wallet

# List wallets
tronctl keys list

# Import private key
tronctl keys import my-wallet --private-key <key>

Next Steps