tron

package module
v0.0.0-...-61460eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 12 Imported by: 0

README

tron-sdk

Tron SDK is used to interact with the Tron blockchain, it contains various functions can be used to web3 wallet.

Installation

go get

To obtain the latest version, simply require the project using :

go get -u github.com/okx/go-wallet-sdk/coins/tron

Usage

New address
pubKeyHex := "0357bbb2d4a9cb8a2357633f201b9c518c2795ded682b7913c6beef3fe23bd6d2f"
publicKey, _ := hex.DecodeString(pubKeyHex)
pub,_:=btcec.ParsePubKey(publicKey)
addr:=GetAddress(pub)
fmt.Println(addr)
Transfer
currentTime := time.Now()
k1 := make([]byte, 8)
binary.BigEndian.PutUint64(k1, 47102802)
k2, _ := hex.DecodeString("0000000002cebb52bb1c53a37236902bac251e302a4541452b6df63f594562b9")
d2, _ := newTransfer(
    "TSAaoJuxBUxSqU7JGxzTH3gx237PTJxfwV",
    "TWYrgz7RDP2NpumQRPY1jBmPKLWVSnrzWZ",
    10000000,
    hex.EncodeToString(k1[6:8]),
    hex.EncodeToString(k2[8:16]),
    currentTime.UnixMilli()+3600*1000,
    currentTime.UnixMilli())

License

Most packages or folder are MIT licensed, see package or folder for the respective license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAddress

func GetAddress(publicKey *btcec.PublicKey) string

func GetAddressByPublicKey

func GetAddressByPublicKey(pubKey string) (string, error)

func GetAddressHash

func GetAddressHash(address string) ([]byte, error)

func GetNetWork

func GetNetWork() []byte

func NewTRC20TokenTransfer

func NewTRC20TokenTransfer(fromAddress string, toAddress string, contractAddress string, amount *big.Int, feeLimit int64, refBlockBytes string, refBlockHash string, expiration int64, timestamp int64) (string, error)

create a TRC20 transfer transaction

func NewTransfer

func NewTransfer(fromAddress string, toAddress string, amount int64, refBlockBytes string, refBlockHash string, expiration int64, timestamp int64) (string, error)
  create a TRC transfer transaction
	 refBlockBytes - transaction reference block height (take 6-7 2 bytes)
	 refBlockHash - block hash referenced by the transaction (take 8-15 8 bytes)
	 expiration - transaction expiration time, beyond this time the transaction will not be packed
	 timestamp - transaction creation time
	 fee_limit - the maximum energy consumption of smart contract transactions, only need to be set when deploying or calling smart contracts

func ParseTxStr

func ParseTxStr(txStr string) (pb.Transaction, error)

func Sign

func Sign(data string, privateKey *btcec.PrivateKey) (string, error)

func SignEnd

func SignEnd(txStr string, txSignStr string) (string, error)

func SignStart

func SignStart(txStr string) (string, error)

func ValidateAddress

func ValidateAddress(address string) bool

Types

type Transaction

type Transaction struct {
	Nonce    *big.Int `json:"nonce"`
	GasLimit *big.Int `json:"gasLimit"`
	GasPrice *big.Int `json:"gasPrice"`
	To       string   `json:"to"`
	Value    float64  `json:"value"`
	Data     []byte   `json:"data"`
	Fee      *big.Int `json:"fee"`
}

type TronTokenTransaction

type TronTokenTransaction struct {
	TronTransaction
	AssetName       string `json:"asset"`
	ContractAddress string `json:"contractAddress"`
	FeeLimit        int64  `json:"feelimit"`
	Trc             string `json:"trc"`
}

type TronTransaction

type TronTransaction struct {
	Transaction
	RefBlockBytes string   `json:"ref_block_bytes"`
	RefBlockHash  string   `json:"ref_block_hash"`
	RefBlockNum   *big.Int `json:"ref_block_number"`
	Timestamp     *big.Int `json:"timestamp"`
	Expiration    *big.Int `json:"expiration"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL