txbuilder

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package txbuilder provides a fluent builder for native TRON transactions (transfers, staking, voting, etc.) with Build / Send / SendAndConfirm terminal operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is the entry point for constructing native TRON transactions. Create one with New, then call transaction methods (Transfer, FreezeV2, etc.) to get a Tx with terminal operations.

func New

func New(client Client, opts ...Option) *Builder

New creates a Builder bound to the given client. Options set shared defaults that apply to every transaction produced by this builder.

func (*Builder) DelegateResource

func (b *Builder) DelegateResource(from, to string, resource core.ResourceCode, amount int64, opts ...Option) *DelegateTx

DelegateResource creates a resource delegation transaction. Use .Lock(period) on the returned DelegateTx to enable delegation locking.

func (*Builder) FreezeV2

func (b *Builder) FreezeV2(from string, amount int64, resource core.ResourceCode, opts ...Option) *Tx

FreezeV2 creates a Stake 2.0 freeze transaction.

func (*Builder) Transfer

func (b *Builder) Transfer(from, to string, amount int64, opts ...Option) *Tx

Transfer creates a TRX transfer transaction.

func (*Builder) UnDelegateResource

func (b *Builder) UnDelegateResource(from, to string, resource core.ResourceCode, amount int64, opts ...Option) *Tx

UnDelegateResource creates a resource un-delegation transaction.

func (*Builder) UnfreezeV2

func (b *Builder) UnfreezeV2(from string, amount int64, resource core.ResourceCode, opts ...Option) *Tx

UnfreezeV2 creates a Stake 2.0 unfreeze transaction.

func (*Builder) VoteWitness

func (b *Builder) VoteWitness(from string, opts ...Option) *VoteTx

VoteWitness creates a witness vote transaction. Add votes using the fluent .Vote() or .Votes() methods on the returned VoteTx.

type Client

type Client interface {
	TransferCtx(ctx context.Context, from, toAddress string, amount int64) (*api.TransactionExtention, error)
	BroadcastCtx(ctx context.Context, tx *core.Transaction) (*api.Return, error)
	GetTransactionInfoByIDCtx(ctx context.Context, id string) (*core.TransactionInfo, error)
	FreezeBalanceV2Ctx(ctx context.Context, from string, resource core.ResourceCode, frozenBalance int64) (*api.TransactionExtention, error)
	UnfreezeBalanceV2Ctx(ctx context.Context, from string, resource core.ResourceCode, unfreezeBalance int64) (*api.TransactionExtention, error)
	DelegateResourceCtx(ctx context.Context, from, to string, resource core.ResourceCode, delegateBalance int64, lock bool, lockPeriod int64) (*api.TransactionExtention, error)
	UnDelegateResourceCtx(ctx context.Context, owner, receiver string, resource core.ResourceCode, delegateBalance int64) (*api.TransactionExtention, error)
	VoteWitnessAccountCtx(ctx context.Context, from string, witnessMap map[string]int64) (*api.TransactionExtention, error)
}

Client is the subset of GrpcClient that transaction builders need. Accepting an interface avoids import cycles and simplifies testing.

type DelegateTx

type DelegateTx struct {
	*Tx
	// contains filtered or unexported fields
}

DelegateTx is a delegation transaction builder with a fluent Lock method. It embeds *Tx so all terminal operations (Build, Send, SendAndConfirm) are available directly.

func (*DelegateTx) Lock

func (d *DelegateTx) Lock(period int64) *DelegateTx

Lock enables the delegation lock with the given period (in blocks). Returns itself for chaining.

type Option

type Option func(*config)

Option configures a Tx.

func WithMemo

func WithMemo(memo string) Option

WithMemo attaches a memo (stored in RawData.Data) to the transaction.

func WithPermissionID

func WithPermissionID(id int32) Option

WithPermissionID sets the permission ID used for multi-signature transactions.

type Receipt

type Receipt = txresult.Receipt

Receipt is an alias for the shared receipt type.

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx represents a single prepared transaction with terminal operations.

func (*Tx) Build

func (t *Tx) Build(ctx context.Context) (*api.TransactionExtention, error)

Build creates the unsigned transaction, applying any configured options (permission ID, memo, etc.).

func (*Tx) Decode

func (t *Tx) Decode(ctx context.Context) (*transaction.ContractData, error)

Decode builds the transaction and decodes the first contract parameter into human-readable fields (base58 addresses, TRX-formatted amounts). Useful for inspecting or displaying what a transaction does before signing.

func (*Tx) Send

func (t *Tx) Send(ctx context.Context, s signer.Signer) (*Receipt, error)

Send builds, signs, and broadcasts the transaction. It returns a Receipt populated from the broadcast response.

func (*Tx) SendAndConfirm

func (t *Tx) SendAndConfirm(ctx context.Context, s signer.Signer) (*Receipt, error)

SendAndConfirm is like Send but additionally polls GetTransactionInfoByID until the transaction is confirmed or the context is cancelled.

type VoteTx

type VoteTx struct {
	*Tx
	// contains filtered or unexported fields
}

VoteTx is a vote transaction builder with fluent methods for adding votes. It embeds *Tx so all terminal operations (Build, Send, SendAndConfirm) are available directly.

func (*VoteTx) Vote

func (v *VoteTx) Vote(witnessAddress string, count int64) *VoteTx

Vote adds a vote for the given witness address. Can be called multiple times to build up the vote set. Returns itself for chaining.

func (*VoteTx) Votes

func (v *VoteTx) Votes(votes map[string]int64) *VoteTx

Votes sets all votes at once from a map. Useful for programmatic vote construction. Merges with any previously added votes.

Jump to

Keyboard shortcuts

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