Documentation ¶
Index ¶
- Constants
- Variables
- func CheckSolTransferTransaction(meta *client.TransactionMeta, tx types.Transaction, destination string, ...) error
- func CheckTokenTransferTransaction(meta *client.TransactionMeta, tx types.Transaction, mint, destination string, ...) error
- func DecodeTransaction(base64Tx string) (types.Transaction, error)
- func EncodeTransaction(tx types.Transaction) (string, error)
- func SignTransaction(txSource string, signer types.Account) (string, error)
- type Balance
- type BurnTokenParams
- type Client
- func (c *Client) DoesTokenAccountExist(ctx context.Context, base58AtaAddr string) (bool, error)
- func (c *Client) GetAtaBalance(ctx context.Context, base58Addr string) (Balance, error)
- func (c *Client) GetFungibleTokenMetadata(ctx context.Context, base58MintAddr string) (result *FungibleTokenMetadata, err error)
- func (c *Client) GetLatestBlockhash(ctx context.Context) (string, error)
- func (c *Client) GetMinimumBalanceForRentExemption(ctx context.Context, size uint64) (uint64, error)
- func (c *Client) GetOldestTransactionForWallet(ctx context.Context, base58Addr string, offsetTxSignature string) (string, *client.GetTransactionResponse, error)
- func (c *Client) GetSOLBalance(ctx context.Context, base58Addr string) (Balance, error)
- func (c *Client) GetTokenBalance(ctx context.Context, base58Addr, base58MintAddr string) (Balance, error)
- func (c *Client) GetTokenSupply(ctx context.Context, base58MintAddr string) (Balance, error)
- func (c *Client) GetTransaction(ctx context.Context, txSignature string) (*client.GetTransactionResponse, error)
- func (c *Client) GetTransactionStatus(ctx context.Context, txhash string) (TransactionStatus, error)
- func (c *Client) RequestAirdrop(ctx context.Context, base58Addr string, amount uint64) (string, error)
- func (c *Client) SendTransaction(ctx context.Context, txSource string) (string, error)
- func (c *Client) ValidateTransactionByReference(ctx context.Context, reference, destination string, amount uint64, mint string) (string, error)
- func (c *Client) WaitForTransactionConfirmed(ctx context.Context, txhash string, maxDuration time.Duration) (TransactionStatus, error)
- type ClientOption
- type CloseTokenAccountParams
- type CreateAssociatedTokenAccountParam
- type CreateFungibleTokenParam
- type FungibleTokenMetadata
- type InstructionFunc
- func BurnToken(params BurnTokenParams) InstructionFunc
- func CloseTokenAccount(params CloseTokenAccountParams) InstructionFunc
- func CreateAssociatedTokenAccountIfNotExists(params CreateAssociatedTokenAccountParam) InstructionFunc
- func CreateFungibleToken(params CreateFungibleTokenParam) InstructionFunc
- func Memo(str string, signers ...string) InstructionFunc
- func MintFungibleToken(params MintFungibleTokenParams) InstructionFunc
- func TransferSOL(params TransferSOLParams) InstructionFunc
- func TransferToken(params TransferTokenParam) InstructionFunc
- func UpdateFungibleMetadata(params UpdateFungibleMetadataParams) InstructionFunc
- type MintFungibleTokenParams
- type SolanaClient
- type TokenList
- type TokenListTag
- type TokenListToken
- type TransactionBuilder
- func (b *TransactionBuilder) AddInstruction(instruction InstructionFunc) *TransactionBuilder
- func (b *TransactionBuilder) AddRawInstructionsToBeginning(instructions ...types.Instruction) *TransactionBuilder
- func (b *TransactionBuilder) AddRawInstructionsToEnd(instructions ...types.Instruction) *TransactionBuilder
- func (b *TransactionBuilder) AddSigner(signer types.Account) *TransactionBuilder
- func (b *TransactionBuilder) Build(ctx context.Context) (string, error)
- func (b *TransactionBuilder) PrepareInstructions(ctx context.Context) ([]types.Instruction, error)
- func (b *TransactionBuilder) SetAddressLookupTableAccount(account types.AddressLookupTableAccount) *TransactionBuilder
- func (b *TransactionBuilder) SetFeePayer(feePayer string) *TransactionBuilder
- func (b *TransactionBuilder) Validate() error
- type TransactionStatus
- type TransferSOLParams
- type TransferTokenParam
- type UpdateFungibleMetadataParams
Constants ¶
const ( ChainIdMainnet = 101 // Mainnet-beta ChainIdTestnet = 102 // Testnet )
Token list chain IDs
Variables ¶
var ( ErrClientNotSet = errors.New("solana rpc client not set") ErrFeePayerNotSet = errors.New("missing or invalid fee payer public key") ErrNoInstruction = errors.New("no instructions added, require at least one instruction") ErrSenderAndRecipientAreSame = errors.New("sender and recipient are the same account") ErrMustBeGreaterThanZero = errors.New("amount must be greater than 0") ErrSenderIsRequired = errors.New("sender wallet address is required") ErrRecipientIsRequired = errors.New("recipient wallet address is required") ErrMintIsRequired = errors.New("mint address is required") ErrMemoCannotBeEmpty = errors.New("memo cannot be empty") ErrGetLatestBlockhash = errors.New("failed to get latest blockhash") ErrTokenAccountDoesNotExist = errors.New("token account does not exist") ErrNoTransactionsFound = errors.New("no transactions found") ErrTransactionNotConfirmed = errors.New("transaction not confirmed") ErrTransactionNotFound = errors.New("transaction not found") )
Predefined package errors.
Functions ¶
func CheckSolTransferTransaction ¶
func CheckSolTransferTransaction(meta *client.TransactionMeta, tx types.Transaction, destination string, amount uint64) error
CheckSolTransferTransaction checks if a transaction is a SOL transfer transaction. Verifies that destination account has been credited with the correct amount.
func CheckTokenTransferTransaction ¶
func CheckTokenTransferTransaction(meta *client.TransactionMeta, tx types.Transaction, mint, destination string, amount uint64) error
CheckTokenTransferTransaction checks if a transaction is a token transfer transaction. Verifies that destination account has been credited with the correct amount of the token.
func DecodeTransaction ¶
func DecodeTransaction(base64Tx string) (types.Transaction, error)
DecodeTransaction returns a transaction from a base64 encoded transaction.
func EncodeTransaction ¶
func EncodeTransaction(tx types.Transaction) (string, error)
EncodeTransaction returns a base64 encoded transaction.
Types ¶
type Balance ¶
type Balance struct { Amount uint64 `json:"amount"` // Balance in minimal units. E.g. 1000000000 (1 SOL) or 1000000 (1 USDC). Decimals uint8 `json:"decimals"` // Number of decimals. E.g. 9 for SOL, 6 for USDC. UIAmount float64 `json:"ui_amount"` // Balance in UI units. E.g. 1 (1 SOL) or 1.000001 (1.000001 USDC). UIAmountString string `json:"ui_amount_string"` // Balance in UI units as a string. E.g. "1" (1 SOL) or "1.000001" (1.000001 USDC). }
Balance represents the balance of a token account or a wallet.
func NewBalance ¶
NewBalance returns a new Balance instance.
type BurnTokenParams ¶
type BurnTokenParams struct { Mint string // base58 encoded public key of the mint TokenAccountOwner string // base58 encoded public key of the token account owner Amount uint64 }
BurnTokenParams are the parameters for the BurnToken instruction.
func (BurnTokenParams) Validate ¶
func (p BurnTokenParams) Validate() error
Validate checks that the required fields of the params are set.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client struct is a wrapper for the solana-go-sdk client. It implements the SolanaClient interface.
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient creates a new Client instance.
func (*Client) DoesTokenAccountExist ¶
DoesTokenAccountExist returns true if the token account exists. Otherwise, it returns false.
func (*Client) GetAtaBalance ¶
GetAtaBalance returns the SPL token balance of the given base58 encoded associated token account address. base58Addr is the base58 encoded associated token account address. Returns the balance in lamports and token decimals, or an error.
func (*Client) GetFungibleTokenMetadata ¶
func (c *Client) GetFungibleTokenMetadata(ctx context.Context, base58MintAddr string) (result *FungibleTokenMetadata, err error)
GetFungibleTokenMetadata returns the on-chain SPL token metadata by the given base58 encoded SPL token mint address. Returns the token metadata or an error.
func (*Client) GetLatestBlockhash ¶
GetLatestBlockhash returns the latest blockhash.
func (*Client) GetMinimumBalanceForRentExemption ¶
func (c *Client) GetMinimumBalanceForRentExemption(ctx context.Context, size uint64) (uint64, error)
GetMinimumBalanceForRentExemption gets the minimum balance for rent exemption. Returns the minimum balance in lamports or an error.
func (*Client) GetOldestTransactionForWallet ¶
func (c *Client) GetOldestTransactionForWallet( ctx context.Context, base58Addr string, offsetTxSignature string, ) (string, *client.GetTransactionResponse, error)
GetOldestTransactionForWallet returns the oldest transaction by the given base58 encoded public key. Returns the transaction or an error.
func (*Client) GetSOLBalance ¶
GetSOLBalance returns the SOL balance in lamports of the given base58 encoded account address. Returns the balance or an error.
func (*Client) GetTokenBalance ¶
func (c *Client) GetTokenBalance(ctx context.Context, base58Addr, base58MintAddr string) (Balance, error)
GetTokenBalance returns the SPL token balance of the given base58 encoded account address and SPL token mint address. base58Addr is the base58 encoded account address. base58MintAddr is the base58 encoded SPL token mint address. Returns the Balance object, or an error.
func (*Client) GetTokenSupply ¶
GetTokenSupply returns the token supply for a given mint address. This is a wrapper around the GetTokenSupply function from the solana-go-sdk. base58MintAddr is the base58 encoded address of the token mint. The function returns the token supply and decimals or an error.
func (*Client) GetTransaction ¶
func (c *Client) GetTransaction(ctx context.Context, txSignature string) (*client.GetTransactionResponse, error)
GetTransaction returns the transaction by the given base58 encoded transaction signature. Returns the transaction or an error.
func (*Client) GetTransactionStatus ¶
func (c *Client) GetTransactionStatus(ctx context.Context, txhash string) (TransactionStatus, error)
GetTransactionStatus gets the transaction status. Returns the transaction status or an error.
func (*Client) RequestAirdrop ¶
func (c *Client) RequestAirdrop(ctx context.Context, base58Addr string, amount uint64) (string, error)
RequestAirdrop sends a request to the solana network to airdrop SOL to the given account. Returns the transaction signature or an error.
func (*Client) SendTransaction ¶
SendTransaction sends a transaction to the network. Returns the transaction signature or an error.
func (*Client) ValidateTransactionByReference ¶
func (c *Client) ValidateTransactionByReference(ctx context.Context, reference, destination string, amount uint64, mint string) (string, error)
ValidateTransactionByReference returns the transaction by the given reference. Returns transaction signature or an error if the transaction is not found or the transaction failed.
func (*Client) WaitForTransactionConfirmed ¶
func (c *Client) WaitForTransactionConfirmed(ctx context.Context, txhash string, maxDuration time.Duration) (TransactionStatus, error)
WaitForTransactionConfirmed waits for a transaction to be confirmed. Returns the transaction status or an error. If maxDuration is 0, it will wait for 5 minutes. Can be useful for testing, but not recommended for production because it may block requests for a long time.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that configures the Client.
func WithRPCClient ¶
func WithRPCClient(rpcClient *client.Client) ClientOption
WithRPCClient sets the rpc client.
func WithRPCEndpoint ¶
func WithRPCEndpoint(endpoint string) ClientOption
WithRPCEndpoint sets the rpc endpoint.
func WithTokenListPath ¶
func WithTokenListPath(path string) ClientOption
WithTokenListPath sets the token list path.
func WithWSClient ¶
func WithWSClient(wsClient *client.Client) ClientOption
WithWSClient sets the ws client.
func WithWSEndpoint ¶
func WithWSEndpoint(endpoint string) ClientOption
WithWSEndpoint sets the ws endpoint.
type CloseTokenAccountParams ¶
type CloseTokenAccountParams struct { Owner string // base58 encoded public key of the owner of the token account. CloseTokenAccount *string // optional; base58 encoded public key of the token account to close; if not set, the associated token account will be derived from the owner and mint. Mint *string // optional; base58 encoded public key of the mint; if not set, the CloseTokenAccount must be set. FeePayer *string // optional; base58 encoded public key of the fee payer of the transaction, if not set, the owner will be used; if set, the rent exemption balance will be transferred to it. }
CloseTokenAccountParams are the parameters for the CloseTokenAccount instruction.
func (CloseTokenAccountParams) Validate ¶
func (p CloseTokenAccountParams) Validate() error
Validate checks that the required fields of the params are set.
type CreateAssociatedTokenAccountParam ¶
type CreateAssociatedTokenAccountParam struct { Funder string // base58 encoded public key of the account that will fund the associated token account. Must be a signer. Owner string // base58 encoded public key of the owner of the associated token account. Must be a signer. Mint string // base58 encoded public key of the mint of the associated token account. }
CreateAssociatedTokenAccountParam defines the parameters for creating an associated token account.
type CreateFungibleTokenParam ¶
type CreateFungibleTokenParam struct { Mint string // required; The token mint public key. Owner string // required; The owner of the token. FeePayer string // required; The wallet to pay the fees from. Decimals uint8 // optional; The number of decimals the token has. Default is 0. MetadataURI string // optional; URI of the token metadata; can be set later TokenName string // optional; Name of the token; used for the token metadata if MetadataURI is not set. TokenSymbol string // optional; Symbol of the token; used for the token metadata if MetadataURI is not set. }
CreateFungibleTokenParam defines the parameters for the CreateFungibleToken instruction.
func (CreateFungibleTokenParam) Validate ¶
func (p CreateFungibleTokenParam) Validate() error
Validate checks that the required fields of the params are set.
type FungibleTokenMetadata ¶
type FungibleTokenMetadata struct { Mint string `json:"mint"` Name string `json:"name"` Symbol string `json:"symbol"` Decimals uint8 `json:"decimals"` LogoURI string `json:"logo_uri"` Description string `json:"description,omitempty"` ExternalURL string `json:"external_url,omitempty"` }
FungibleTokenMetadata represents the metadata of a fungible token.
type InstructionFunc ¶
type InstructionFunc func(ctx context.Context, c SolanaClient) ([]types.Instruction, error)
InstructionFunc is a function that returns a list of prepared instructions.
func BurnToken ¶
func BurnToken(params BurnTokenParams) InstructionFunc
BurnToken burns the specified token.
func CloseTokenAccount ¶
func CloseTokenAccount(params CloseTokenAccountParams) InstructionFunc
CloseTokenAccount closes the specified token account.
func CreateAssociatedTokenAccountIfNotExists ¶
func CreateAssociatedTokenAccountIfNotExists(params CreateAssociatedTokenAccountParam) InstructionFunc
CreateAssociatedTokenAccountIfNotExists creates an associated token account for the given owner and mint if it does not exist.
func CreateFungibleToken ¶
func CreateFungibleToken(params CreateFungibleTokenParam) InstructionFunc
CreateFungibleToken creates instructions for minting fungible tokens or assets. The token mint account must be created before calling this function. To mint common fungible tokens, decimals must be greater than 0. If decimals is 0, the token is fungible asset.
func Memo ¶
func Memo(str string, signers ...string) InstructionFunc
Memo returns a list of instructions that can be used to add a memo to transaction.
func MintFungibleToken ¶
func MintFungibleToken(params MintFungibleTokenParams) InstructionFunc
MintFungibleToken mints the fungible token.
func TransferSOL ¶
func TransferSOL(params TransferSOLParams) InstructionFunc
TransferSOL transfers SOL from one wallet to another. Note: This function does not check if the sender has enough SOL to send. It is the responsibility of the caller to check this. Amount must be greater than minimum account rent exemption (~0.0025 SOL).
func TransferToken ¶
func TransferToken(params TransferTokenParam) InstructionFunc
TransferToken transfers tokens from one wallet to another. Note: This function does not check if the sender has enough tokens to send. It is the responsibility of the caller to check this. FeePayer must be provided if Sender is not set.
func UpdateFungibleMetadata ¶
func UpdateFungibleMetadata(params UpdateFungibleMetadataParams) InstructionFunc
UpdateFungibleMetadata updates the metadata of the fungible token.
type MintFungibleTokenParams ¶
type MintFungibleTokenParams struct { Funder string // base58 encoded public key of the account that will fund the associated token account. Must be a signer. Mint string // base58 encoded public key of the mint MintOwner string // base58 encoded public key of the mint owner MintTo string // base58 encoded public key of the account that will receive the minted tokens Amount uint64 // amount of tokens to mint in basis points, for example, 1 token with 9 decimals = 1000000000 bps. }
MintFungibleTokenParams is the params for MintFungibleToken
func (MintFungibleTokenParams) Validate ¶
func (p MintFungibleTokenParams) Validate() error
Validate validates the params.
type SolanaClient ¶
type SolanaClient interface { GetLatestBlockhash(ctx context.Context) (string, error) DoesTokenAccountExist(ctx context.Context, base58AtaAddr string) (bool, error) GetMinimumBalanceForRentExemption(ctx context.Context, size uint64) (uint64, error) }
SolanaClient is an RPC client for Solana.
type TokenList ¶
type TokenList struct { Name string `json:"name"` LogoURI string `json:"logoURI"` Keywords []string `json:"keywords"` Tags map[string]TokenListTag `json:"tags"` Tokens []TokenListToken `json:"tokens"` }
@deprecated This is a temporary solution to support the deprecated metadata format.
type TokenListTag ¶
@deprecated This is a temporary solution to support the deprecated metadata format.
type TokenListToken ¶
type TokenListToken struct { ChainID int `json:"chainId"` Address string `json:"address"` Symbol string `json:"symbol"` Name string `json:"name"` Decimals int `json:"decimals"` LogoURI string `json:"logoURI"` Tags []string `json:"tags,omitempty"` Extensions map[string]interface{} `json:"extensions,omitempty"` }
@deprecated This is a temporary solution to support the deprecated metadata format.
type TransactionBuilder ¶
type TransactionBuilder struct {
// contains filtered or unexported fields
}
TransactionBuilder is a builder for Transaction.
func NewTransactionBuilder ¶
func NewTransactionBuilder(client SolanaClient) *TransactionBuilder
NewTransactionBuilder creates a new TransactionBuilder instance.
func (*TransactionBuilder) AddInstruction ¶
func (b *TransactionBuilder) AddInstruction(instruction InstructionFunc) *TransactionBuilder
AddInstruction adds a new instruction to the transaction.
func (*TransactionBuilder) AddRawInstructionsToBeginning ¶
func (b *TransactionBuilder) AddRawInstructionsToBeginning(instructions ...types.Instruction) *TransactionBuilder
AddRawInstructionsToBeginning adds raw instructions to the beginning of the transaction.
func (*TransactionBuilder) AddRawInstructionsToEnd ¶
func (b *TransactionBuilder) AddRawInstructionsToEnd(instructions ...types.Instruction) *TransactionBuilder
AddRawInstructionsToEnd adds raw instructions to the end of the transaction.
func (*TransactionBuilder) AddSigner ¶
func (b *TransactionBuilder) AddSigner(signer types.Account) *TransactionBuilder
AddSigner adds a signer account to the transaction. The signer account must be added before calling Build().
func (*TransactionBuilder) Build ¶
func (b *TransactionBuilder) Build(ctx context.Context) (string, error)
Build builds a new transaction with the given instructions. It returns base64 encoded transaction or an error.
func (*TransactionBuilder) PrepareInstructions ¶
func (b *TransactionBuilder) PrepareInstructions(ctx context.Context) ([]types.Instruction, error)
PrepareInstructions prepares the instructions for the transaction. It returns a list of prepared instructions or an error.
func (*TransactionBuilder) SetAddressLookupTableAccount ¶
func (b *TransactionBuilder) SetAddressLookupTableAccount(account types.AddressLookupTableAccount) *TransactionBuilder
SetAddressLookupTableAccount adds a new address lookup table account to the transaction.
func (*TransactionBuilder) SetFeePayer ¶
func (b *TransactionBuilder) SetFeePayer(feePayer string) *TransactionBuilder
SetFeePayer sets the fee payer for the transaction.
func (*TransactionBuilder) Validate ¶
func (b *TransactionBuilder) Validate() error
Validate validates the transaction builder.
type TransactionStatus ¶
type TransactionStatus uint8
TransactionStatus represents the status of a transaction.
const ( TransactionStatusUnknown TransactionStatus = iota TransactionStatusSuccess TransactionStatusInProgress TransactionStatusFailure )
TransactionStatus enum.
func ParseTransactionStatus ¶
func ParseTransactionStatus(s rpc.Commitment) TransactionStatus
ParseTransactionStatus parses the transaction status from the given string.
func (TransactionStatus) String ¶
func (s TransactionStatus) String() string
String returns the string representation of the transaction status.
type TransferSOLParams ¶
type TransferSOLParams struct { Sender string // required; base58 encoded public key of the sender. Must be a signer. Recipient string // required; base58 encoded public key of the recipient. Reference string // optional; base58 encoded public key to use as a reference for the transaction. Amount uint64 // required; the amount of SOL to send (in lamports). Must be greater than minimum account rent exemption (~0.0025 SOL). }
TransferSOLParams defines the parameters for transferring SOL.
func (TransferSOLParams) Validate ¶
func (p TransferSOLParams) Validate() error
Validate validates the parameters.
type TransferTokenParam ¶
type TransferTokenParam struct { Sender string // required; base58 encoded public key of the sender. Must be a signer. Recipient string // required; base58 encoded public key of the recipient. Mint string // required; base58 encoded public key of the mint of the token to send. Reference string // optional; base58 encoded public key to use as a reference for the transaction. Amount uint64 // required; the amount of tokens to send (in token minimal units), e.g. 1 USDT = 1000000 (10^6) lamports. }
TransferTokenParam defines the parameters for transferring tokens.
func (TransferTokenParam) Validate ¶
func (p TransferTokenParam) Validate() error
Validate validates the parameters.
type UpdateFungibleMetadataParams ¶
type UpdateFungibleMetadataParams struct { Mint string // required; The mint address of the token UpdateAuthority string // required; The update authority of the token MetadataUri string // optional; new metadata json uri }
UpdateFungibleMetadataParams is the params for UpdateMetadata
func (UpdateFungibleMetadataParams) Validate ¶
func (p UpdateFungibleMetadataParams) Validate() error
Validate validates the params.