web3

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAddress  = errors.New("invalid blockchain address format")
	ErrInvalidChain    = errors.New("unsupported or invalid blockchain network")
	ErrInsufficientGas = errors.New("insufficient funds for gas")
	ErrTxFailed        = errors.New("transaction failed on chain")
)

Common errors in the Web3 domain.

Functions

func NormalizeAddress

func NormalizeAddress(address string) string

NormalizeAddress ensures addresses are stored in a consistent format (lowercase for EVM).

Types

type Balance

type Balance struct {
	WalletAddress   string    `json:"wallet_address"`
	ContractAddress string    `json:"contract_address,omitempty"` // Empty for native currency
	Chain           Chain     `json:"chain"`
	Amount          string    `json:"amount"` // Raw amount (Wei/Lamports)
	Decimals        int       `json:"decimals"`
	Symbol          string    `json:"symbol"`
	UpdatedAt       time.Time `json:"updated_at"`
}

Balance represents a snapshot of an asset holding.

func (*Balance) IsNative

func (b *Balance) IsNative() bool

IsNative returns true if the balance represents the chain's native currency.

type Chain

type Chain string

Chain represents a supported blockchain network.

func (Chain) String

func (c Chain) String() string

String returns the string representation of the chain.

type Collection

type Collection struct {
	ContractAddress string    `json:"contract_address"`
	Chain           Chain     `json:"chain"`
	Name            string    `json:"name"`
	Symbol          string    `json:"symbol"`
	Standard        TokenType `json:"standard"`
	Verified        bool      `json:"verified"`
}

Collection represents a grouping of NFTs (Smart Contract).

type MainnetChain

type MainnetChain Chain
const (
	ChainEthereum MainnetChain = "ethereum"
	ChainPolygon  MainnetChain = "polygon"
	ChainBSC      MainnetChain = "bsc"
	ChainSolana   MainnetChain = "solana"
	ChainArbitrum MainnetChain = "arbitrum"
	ChainOptimism MainnetChain = "optimism"
)

type NFT

type NFT struct {
	ID              string                 `json:"id"`
	ContractAddress string                 `json:"contract_address"`
	TokenID         string                 `json:"token_id"` // String to handle large big.Int values
	Chain           Chain                  `json:"chain"`
	Standard        TokenType              `json:"standard"`
	OwnerAddress    string                 `json:"owner_address"`
	Name            string                 `json:"name"`
	Description     string                 `json:"description"`
	ImageURL        string                 `json:"image_url"`
	Metadata        map[string]interface{} `json:"metadata,omitempty"`
	MintedAt        *time.Time             `json:"minted_at,omitempty"`
	LastSyncedAt    time.Time              `json:"last_synced_at"`
}

NFT represents a Non-Fungible Token asset.

type TokenType

type TokenType string

TokenType distinguishes between different token standards.

const (
	TokenTypeNative  TokenType = "NATIVE"
	TokenTypeERC20   TokenType = "ERC20"
	TokenTypeERC721  TokenType = "ERC721"
	TokenTypeERC1155 TokenType = "ERC1155"
	TokenTypeSPL     TokenType = "SPL" // Solana Program Library
)

type Transaction

type Transaction struct {
	ID            string            `json:"id"`
	Hash          string            `json:"hash"`
	Chain         Chain             `json:"chain"`
	FromAddress   string            `json:"from_address"`
	ToAddress     string            `json:"to_address"`
	Value         string            `json:"value"` // Amount in Wei/Lamports as string
	GasPrice      string            `json:"gas_price,omitempty"`
	GasUsed       uint64            `json:"gas_used,omitempty"`
	Nonce         uint64            `json:"nonce"`
	BlockNumber   uint64            `json:"block_number,omitempty"`
	BlockHash     string            `json:"block_hash,omitempty"`
	Status        TransactionStatus `json:"status"`
	InputData     string            `json:"input_data,omitempty"` // Hex encoded input data
	Confirmations uint64            `json:"confirmations"`
	Timestamp     time.Time         `json:"timestamp"`
}

Transaction represents a state change on the blockchain.

func (*Transaction) ExplorerURL

func (tx *Transaction) ExplorerURL() string

ExplorerURL returns the public block explorer URL for this transaction.

func (*Transaction) IsConfirmed

func (tx *Transaction) IsConfirmed() bool

IsConfirmed checks if the transaction is considered final based on status.

type TransactionStatus

type TransactionStatus string

TransactionStatus represents the lifecycle state of a blockchain transaction.

const (
	TxStatusPending   TransactionStatus = "PENDING"
	TxStatusConfirmed TransactionStatus = "CONFIRMED"
	TxStatusFailed    TransactionStatus = "FAILED"
	TxStatusDropped   TransactionStatus = "DROPPED"
)

type Wallet

type Wallet struct {
	ID          string    `json:"id"`
	UserID      string    `json:"user_id"`
	Address     string    `json:"address"`
	Chain       Chain     `json:"chain"`
	Label       string    `json:"label,omitempty"`
	IsCustodial bool      `json:"is_custodial"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Wallet represents a user's cryptographic wallet on a specific chain.

func NewWallet

func NewWallet(id, userID, address string, chain Chain, custodial bool) (*Wallet, error)

NewWallet creates a new Wallet instance with validation.

func (*Wallet) Validate

func (w *Wallet) Validate() error

Validate checks if the wallet address format is valid for the given chain.

Jump to

Keyboard shortcuts

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