token

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 14 Imported by: 0

README

🪙 sol-token

A Golang package for creating and managing ERC20-like SPL tokens on the Solana blockchain.

Easily mint, transfer, and manage tokens with optional metadata and supply locking. Built with blocto/solana-go-sdk.


✨ Features

  • ✅ Mint new SPL tokens (ERC20-style)
  • ✅ Set name, symbol, URI, decimals, and custom metadata
  • ✅ Transfer tokens between accounts
  • ✅ Automatically create associated token accounts (ATA)
  • ✅ Lock mint authority (disable future minting)
  • ✅ Optional freeze authority support
  • ✅ Lightweight and developer-friendly

🛠️ Installation

go get github.com/ja7ad/sol-token

🚀 Quick Start

client := NewClient(Devnet)
owner := token.NewAccount()
payer := token.NewAccount()
tok := token.NewTokenManager(client, owner, payer)

mintAddr, txHash, err := tok.Mint(ctx, token.MintParams{
    Metadata: token.Metadata{
        Name:     "MyToken",
        Symbol:   "MTK",
        URI:      "https://example.com/token.json",
        Supply:   1000.0,
    },
    DisableFutureMinting: true,
})

Transfer tokens:

_, err = tok.Transfer(ctx, TransferParams{
		Amount:            amount,
		Recipient:         recipient.PublicKey(),
		CheckTokenProgram: true,
	})

🔐 Security Notes

  • Only store the mint account private key if you plan to mint more tokens later.
  • If DisableFutureMinting is true, minting will be permanently disabled.

🌐 Resources

Documentation

Index

Constants

View Source
const (
	// Devnet solana devnet rpc
	Devnet string = rpc.DevnetRPCEndpoint
	// Testnet solana testnet rpc
	Testnet string = rpc.TestnetRPCEndpoint
)

Variables

This section is empty.

Functions

func ConvertToDecimals

func ConvertToDecimals(human float64, decimals uint8) uint64

func ConvertToLamport

func ConvertToLamport(amount float64) uint64

Types

type Account

type Account struct {
	types.Account
}

func NewAccount

func NewAccount() *Account

func NewAccountFromBase58

func NewAccountFromBase58(privBase58 string) (*Account, error)

func NewAccountFromHex

func NewAccountFromHex(privHex string) (*Account, error)

func (*Account) PrivateKey

func (a *Account) PrivateKey() ed25519.PrivateKey

func (*Account) PublicKey

func (a *Account) PublicKey() common.PublicKey

type Client

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

func NewClient

func NewClient(rpc string) *Client

func (*Client) Client

func (c *Client) Client() *client.Client

func (*Client) GetFaucet

func (c *Client) GetFaucet(ctx context.Context, acc *Account, amount float64) (string, error)

func (*Client) IsHealthy

func (c *Client) IsHealthy() bool

type Metadata

type Metadata struct {
	Name   string
	Symbol string
	URI    string
	Supply float64
}

type MintParams

type MintParams struct {
	Metadata             Metadata
	DisableFutureMinting bool
	EnableFreeze         bool
}

type Token

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

func NewTokenManager

func NewTokenManager(client *Client, owner, payer *Account, tokenAddr common.PublicKey) *Token

NewTokenManager create token to mint or transfer exists token token field can nil if not exists.

func (*Token) Mint

func (t *Token) Mint(ctx context.Context, params MintParams) (tokenAddr common.PublicKey, txHash string, err error)

func (*Token) Token

func (t *Token) Token() common.PublicKey

func (*Token) Transfer

func (t *Token) Transfer(ctx context.Context, params TransferParams) (string, error)

type TransferParams

type TransferParams struct {
	Recipient         common.PublicKey // Recipient receiver address
	Amount            float64
	CheckTokenProgram bool // CheckTokenProgram check token initialized on chain before create transfer program
}

Jump to

Keyboard shortcuts

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