solana

package module
v0.0.0-...-61460eb Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 11 Imported by: 0

README

solana-sdk

Solana SDK is used to interact with the Solana blockchain, it contains various functions can be used to web3 wallet.

Installation

go get

To obtain the latest version, simply require the project using :

go get -u github.com/okx/go-wallet-sdk/coins/solana

Usage

New Address
    pk, _ := base.NewRandomPrivateKey()
	address, err := NewAddress(hex.EncodeToString(pk.Bytes()))
    if err != nil {
        // todo
    }
Transfer
	fromPrivate, _ := base.PrivateKeyFromBase58("tzyJiBd5PzFPFfVnnfVx14rsfC8FKW8idpJwNhH6FxzZAdhgBp4CrDxcUW9D89f5k3W6WhVnybbAw7RRB2HPxnt")
	to := "7NRmECq1R4tCtXNvmvDAuXmii3vN1J9DRZWhMCuuUnkM"
	hash := "Cfudd6AiXTzPYrmEBGNFsHgaNKJ3xrrsGCT39avLkoiu"
	// FZNZLT5diWHooSBjcng9qitykwcL9v3RiNrpC3fp9PU1
	from := fromPrivate.PublicKey().String()
	rawTransaction := NewRawTransaction(hash, from)
	rawTransaction.AppendTransferInstruction(1000000000, from, to)
	rawTransaction.AppendSigner(hex.EncodeToString(fromPrivate.Bytes()))
	tx, err := rawTransaction.Sign(true)
	if err != nil {
		// todo
	}
Transfer Token
	hash := "H6TNM3fDg5wTYT4eiv2PnGdd1555a45FEJtxVLtzv9dJ"
	fromPrivate, _ := base.PrivateKeyFromBase58("tzyJiBd5PzFPFfVnnfVx14rsfC8FKW8idpJwNhH6FxzZAdhgBp4CrDxcUW9D89f5k3W6WhVnybbAw7RRB2HPxnt")
	from := fromPrivate.PublicKey().String()
	to := "7NRmECq1R4tCtXNvmvDAuXmii3vN1J9DRZWhMCuuUnkM"
	mint := "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
	fromAssociated, _, _ := base.FindAssociatedTokenAddress(base.MustPublicKeyFromBase58(from), base.MustPublicKeyFromBase58(mint))
	toAssociated, _, _ := base.FindAssociatedTokenAddress(base.MustPublicKeyFromBase58(to), base.MustPublicKeyFromBase58(mint))
	rawTransaction := NewRawTransaction(hash, from)
	rawTransaction.AppendAssociatedTokenAccountCreateInstruction(from, to, mint)
	rawTransaction.AppendTokenTransferInstruction(1000000, fromAssociated.String(), toAssociated.String(), from)
	rawTransaction.AppendSigner(hex.EncodeToString(fromPrivate.Bytes()))
	tx, err := rawTransaction.Sign(true)
	if err != nil {
		// todo
	}

License

Most packages or folder are MIT licensed, see package or folder for the respective license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAndMultiSign

func DecodeAndMultiSign(unsignedTx string, privateKey string, recentBlockHash string, base58 bool) (string, error)

func DecodeAndSign

func DecodeAndSign(txRaw string, signers []string, recentBlockHash string, base58 bool) (string, error)

func GetSigningHash

func GetSigningHash(hash, from, to, nonceAddress string, amount uint64) (string, error)

func NewAddress

func NewAddress(privateKeyHex string) (string, error)

func NewAddressByPublic

func NewAddressByPublic(pubKey string) (string, error)

func SignedTx

func SignedTx(hash, from, to, nonceAddress string, amount uint64, signData string) (string, error)

func ValidateAddress

func ValidateAddress(address string) bool

Types

type RawTransaction

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

func NewRawTransaction

func NewRawTransaction(blockHash string, payer string) *RawTransaction

func (*RawTransaction) AppendAdvanceNonceInstruction

func (t *RawTransaction) AppendAdvanceNonceInstruction(authorized string, nonceAccount string)

func (*RawTransaction) AppendAllocateInstruction

func (t *RawTransaction) AppendAllocateInstruction(
	space uint64,
	newAccount string)

func (*RawTransaction) AppendAssignInstruction

func (t *RawTransaction) AppendAssignInstruction(
	owner string,
	assignedAccount string)

func (*RawTransaction) AppendAssociatedTokenAccountCreateInstruction

func (t *RawTransaction) AppendAssociatedTokenAccountCreateInstruction(payer string, walletAddress string, splTokenMintAddress string, options ...string)

func (*RawTransaction) AppendAuthorizeNonceAccountInstruction

func (t *RawTransaction) AppendAuthorizeNonceAccountInstruction(
	authorized string,
	nonceAccount string,
	nonceAuthorityAccount string)

func (*RawTransaction) AppendCloseAccountInstruction

func (t *RawTransaction) AppendCloseAccountInstruction(
	account string,
	destination string,
	owner string)

func (*RawTransaction) AppendCreateAccountInstruction

func (t *RawTransaction) AppendCreateAccountInstruction(
	lamports uint64,
	space uint64,
	owner string,
	fundingAccount string,
	newAccount string)

func (*RawTransaction) AppendFreezeAccountInstruction

func (t *RawTransaction) AppendFreezeAccountInstruction(
	account string,
	mint string,
	authority string)

func (*RawTransaction) AppendInitializeAccount2Instruction

func (t *RawTransaction) AppendInitializeAccount2Instruction(
	account string,
	mint string,
	owner string)

func (*RawTransaction) AppendInitializeAccount3Instruction

func (t *RawTransaction) AppendInitializeAccount3Instruction(
	account string,
	mint string,
	owner string)

func (*RawTransaction) AppendInitializeAccountInstruction

func (t *RawTransaction) AppendInitializeAccountInstruction(
	account string,
	mint string,
	owner string)

func (*RawTransaction) AppendInitializeMintInstruction

func (t *RawTransaction) AppendInitializeMintInstruction(
	decimals uint8,
	mint_authority string,
	freeze_authority string,
	mint string,
	options ...string)

func (*RawTransaction) AppendInitializeNonceAccountInstruction

func (t *RawTransaction) AppendInitializeNonceAccountInstruction(authorized string, nonceAccount string)

func (*RawTransaction) AppendInstruction

func (t *RawTransaction) AppendInstruction(inst base.Instruction)

func (*RawTransaction) AppendPriorityFeeInstruction

func (t *RawTransaction) AppendPriorityFeeInstruction(computeUnitLimit uint32, computeUnitPrice uint64)

func (*RawTransaction) AppendRevokeInstruction

func (t *RawTransaction) AppendRevokeInstruction(
	source string,
	owner string)

func (*RawTransaction) AppendSetAuthorityInstruction

func (t *RawTransaction) AppendSetAuthorityInstruction(
	authority_type token.AuthorityType,
	new_authority string,

	subject string,
	authority string)

func (*RawTransaction) AppendSigner

func (t *RawTransaction) AppendSigner(privateKeyHex string)

func (*RawTransaction) AppendThawAccountInstruction

func (t *RawTransaction) AppendThawAccountInstruction(
	account string,
	mint string,
	authority string)

func (*RawTransaction) AppendTokenApproveCheckedInstruction

func (t *RawTransaction) AppendTokenApproveCheckedInstruction(
	amount uint64,
	decimals uint8,
	source string,
	mint string,
	delegate string,
	owner string)

func (*RawTransaction) AppendTokenApproveInstruction

func (t *RawTransaction) AppendTokenApproveInstruction(
	amount uint64,

	source string,
	delegate string,
	owner string)

func (*RawTransaction) AppendTokenBurnCheckedInstruction

func (t *RawTransaction) AppendTokenBurnCheckedInstruction(

	amount uint64,
	decimals uint8,

	source string,
	mint string,
	owner string,
	options ...string)

func (*RawTransaction) AppendTokenBurnInstruction

func (t *RawTransaction) AppendTokenBurnInstruction(amount uint64, source string, mint string, owner string, options ...string)

func (*RawTransaction) AppendTokenInitializeMint2Instruction

func (t *RawTransaction) AppendTokenInitializeMint2Instruction(
	decimals uint8,
	mint_authority string,
	freeze_authority string,
	mint string,
	options ...string)

func (*RawTransaction) AppendTokenMintToCheckedInstruction

func (t *RawTransaction) AppendTokenMintToCheckedInstruction(
	amount uint64,
	decimals uint8,

	mint string,
	destination string,
	authority string,
	options ...string)

func (*RawTransaction) AppendTokenMintToInstruction

func (t *RawTransaction) AppendTokenMintToInstruction(
	amount uint64,
	mint string,
	destination string,
	authority string,
	options ...string)

func (*RawTransaction) AppendTokenTransferCheckedInstruction

func (t *RawTransaction) AppendTokenTransferCheckedInstruction(amount uint64, decimals uint8,
	source string,
	mint string,
	destination string,
	owner string,
	options ...string)

func (*RawTransaction) AppendTokenTransferInstruction

func (t *RawTransaction) AppendTokenTransferInstruction(
	amount uint64,
	source string,
	destination string,
	owner string,
	options ...string)

func (*RawTransaction) AppendTransferInstruction

func (t *RawTransaction) AppendTransferInstruction(
	lamports uint64,
	fundingAccount string,
	recipientAccount string)

func (*RawTransaction) AppendWithdrawNonceAccountInstruction

func (t *RawTransaction) AppendWithdrawNonceAccountInstruction(
	lamports uint64,
	nonceAccount string,
	recipientAccount string,
	nonceAuthorityAccount string) error

func (*RawTransaction) Sign

func (t *RawTransaction) Sign(base58 bool) (string, error)

func (*RawTransaction) UnsignedTx

func (t *RawTransaction) UnsignedTx() (string, error)

type UnsignedTx

type UnsignedTx struct {
	BizType string
	Data    string
	BizId   []string
}

Directories

Path Synopsis
Package field implements fast arithmetic modulo 2^255-19.
Package field implements fast arithmetic modulo 2^255-19.

Jump to

Keyboard shortcuts

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