neptoken

package
v0.105.1 Latest Latest
Warning

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

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

Documentation

Overview

Package neptoken contains RPC wrapper for common NEP-11 and NEP-17 methods.

All of these methods are safe, read-only.

Index

Constants

View Source
const (
	// MaxValidDecimals is the maximum value 'decimals' contract method can
	// return to be considered as valid. It's log10(2^256), higher values
	// don't make any sense on a VM with 256-bit integers. This restriction
	// is not imposed by NEP-17 or NEP-11, but we do it as a sanity check
	// anyway (and return plain int as a result).
	MaxValidDecimals = 77
)

Variables

This section is empty.

Functions

func Info added in v0.99.3

func Info(c InfoClient, hash util.Uint160) (*wallet.Token, error)

Info allows to get basic token info using RPC client.

Types

type Base

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

Base is a reader interface for common NEP-11 and NEP-17 methods built on top of Invoker.

func New

func New(invoker Invoker, hash util.Uint160) *Base

New creates an instance of Base for contract with the given hash using the given invoker.

func (*Base) BalanceOf added in v0.99.3

func (b *Base) BalanceOf(account util.Uint160) (*big.Int, error)

BalanceOf returns the token balance of the given account. For NEP-17 that's the token balance with decimals (1 TOK with 2 decimals will lead to 100 returned from this method). For non-divisible NEP-11 that's the number of NFTs owned by the account, for divisible NEP-11 that's the sum of the parts of all NFTs owned by the account.

func (*Base) Decimals

func (b *Base) Decimals() (int, error)

Decimals implements `decimals` NEP-17 or NEP-11 method and returns the number of decimals used by token. For non-divisible NEP-11 tokens this method always returns zero. Values less than 0 or more than MaxValidDecimals are considered to be invalid (with an appropriate error) even if returned by the contract.

func (*Base) Symbol

func (b *Base) Symbol() (string, error)

Symbol implements `symbol` NEP-17 or NEP-11 method and returns a short token identifier (like "NEO" or "GAS").

func (*Base) TotalSupply

func (b *Base) TotalSupply() (*big.Int, error)

TotalSupply returns the total token supply currently available (the amount of minted tokens).

type InfoClient added in v0.99.3

type InfoClient interface {
	invoker.RPCInvoke

	GetContractStateByHash(hash util.Uint160) (*state.Contract, error)
}

InfoClient is a set of RPC methods required to get all of the NEP-11/NEP-17 token data.

type Invoker

type Invoker interface {
	Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
}

Invoker is used by Base to call various methods.

Jump to

Keyboard shortcuts

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