avax

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

avax-sdk

Avax SDK is used to interact with the Aptos 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/avax

Usage

New Address
	// address
	pk, _ := hex.DecodeString("d27a851e2ffe50d81d639a5bc17ccb488b1441307fea7636e264b9da0ce577a1")
	_, b := btcec.PrivKeyFromBytes(pk)
	addr, err := avax.NewAddress("X", "fuji", b)
	if err != nil {
		// todo
		fmt.Println(err)
	}

Transfer
	// transfer
	var inputs []avax.TransferInput
	var outputs []avax.TransferOutPut

	c := math.Pow10(9)
	inputs = append(inputs, avax.TransferInput{TxId: "sJNJVJQzmjyrAoPfshkDhKNf55jNSNW7NXK8SygGdNrst2waA", Index: 0, Amount: uint64(2 * c), AssetId: "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK", PrivateKey: "bf77591baae00a9b2826ae63d6668fe5c1cd934fcaf5c99946af9d55457533ce"})
	outputs = append(outputs, avax.TransferOutPut{Address: "X-fuji1xqq48uejmydn95dwmvk4ge7rs9mj60nlx94dst", AssetId: "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK", Value: uint64(c)})
	outputs = append(outputs, avax.TransferOutPut{Address: "X-fuji1asep0ygju0g2trqq2pvpez736gngthh29lkazf", AssetId: "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK", Value: uint64(0.99 * c)})

	ret, err := avax.NewTransferTransaction(5, "2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm", &inputs, &outputs)
	if err != nil {
		// todo
		fmt.Println(err)
	}
	fmt.Println(ret)

License

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

Documentation

Index

Constants

View Source
const (
	ShortLen = 2
	IntLen   = 4
	LongLen  = 8
)
View Source
const (
	BASETX          = 0
	SECPINPUTID     = 5
	SECPOUTPUTID    = 7
	SECPCREDENTIAL  = 9
	CHAINID_X       = "X"
	HRP_FUJI        = "fuji"
	NETWORK_FUJI    = 5
	BLOCKCHAIN_FUJI = "2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm"
	ASSET_AVAX_FUJI = "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK"
)

Variables

This section is empty.

Functions

func C58Encode

func C58Encode(input []byte) string

func CheckDecodeWithCheckSumLast

func CheckDecodeWithCheckSumLast(input string) (result []byte, err error)

CheckDecodeWithCheckSumLast decodes a string that was encoded with CheckEncode and verifies the checksum.

func NewAddress

func NewAddress(chainId string, hrp string, publicKey *btcec.PublicKey) (string, error)

func NewTransferTransaction

func NewTransferTransaction(netWorkId uint32, blockchainId string, inputs *[]TransferInput, outputs *[]TransferOutPut) (string, error)

func ParseAddress

func ParseAddress(address string) ([]byte, string, string, error)

ParseAddress returned value: (address, chainId, hrp, error)

Types

type Credential

type Credential struct {
	Signature    []byte
	CredentialId uint32
}

type Serializer

type Serializer struct {
	MaxLen int
	Body   []byte
	Offset int
	// contains filtered or unexported fields
}

func NewSerializer

func NewSerializer() *Serializer

func (*Serializer) Add

func (c *Serializer) Add(errors ...error)

func (*Serializer) AddCap

func (c *Serializer) AddCap(bytes int)

func (*Serializer) Check

func (c *Serializer) Check(bytes int)

func (*Serializer) Errored

func (c *Serializer) Errored() bool

func (*Serializer) Payload

func (c *Serializer) Payload() []byte

func (*Serializer) ReadBytes

func (c *Serializer) ReadBytes() []byte

func (*Serializer) ReadFixedBytes

func (c *Serializer) ReadFixedBytes(size int) []byte

func (*Serializer) ReadInt

func (c *Serializer) ReadInt() uint32

func (*Serializer) ReadLong

func (c *Serializer) ReadLong() uint64

func (*Serializer) ReadShort

func (c *Serializer) ReadShort() uint16

func (*Serializer) WriteBytes

func (c *Serializer) WriteBytes(bytes []byte)

func (*Serializer) WriteFixedBytes

func (c *Serializer) WriteFixedBytes(bytes []byte)

func (*Serializer) WriteInt

func (c *Serializer) WriteInt(val uint32)

func (*Serializer) WriteLong

func (c *Serializer) WriteLong(val uint64)

func (*Serializer) WriteShort

func (c *Serializer) WriteShort(val uint16, bigEndian bool)

type Transaction

type Transaction struct {
	Codecid      uint32
	TypeId       uint32
	NetworkID    uint32
	BlockchainID []byte
	Outs         outputSlices
	Ins          inputSlices
	Memo         [4]byte
	Credentials  []Credential
}

func (*Transaction) AddInput

func (t *Transaction) AddInput(txId string, index uint32, amount uint64, assetId string, privateKey string) error

func (*Transaction) AddOutput

func (t *Transaction) AddOutput(address string, value uint64, assetId string) error

func (*Transaction) SerializeToBytes

func (t *Transaction) SerializeToBytes(sl *Serializer) error

type TransferInput

type TransferInput struct {
	TxId       string
	Index      uint32
	Amount     uint64
	AssetId    string
	PrivateKey string
}

type TransferOutPut

type TransferOutPut struct {
	Address string
	Value   uint64
	AssetId string
}

type TransferableInput

type TransferableInput struct {
	TxID       []byte
	UtxoIndex  uint32
	AssetID    []byte
	Input      TxInput
	PrivateKey string
}

func (*TransferableInput) SerializeToBytes

func (t *TransferableInput) SerializeToBytes(sl *Serializer) error

type TransferableOutput

type TransferableOutput struct {
	AssetID []byte
	Output  TxOutput
}

func (*TransferableOutput) SerializeToBytes

func (t *TransferableOutput) SerializeToBytes(sl *Serializer) error

type TxInput

type TxInput struct {
	TypeID       uint32
	Amount       uint64
	AddressIndic uint32
}

func (*TxInput) SerializeToBytes

func (t *TxInput) SerializeToBytes(sl *Serializer)

type TxOutput

type TxOutput struct {
	TypeID     uint32
	Amount     uint64
	Locktime   uint64
	Threshold  uint32
	PubKeyHash []byte
}

func (*TxOutput) SerializeToBytes

func (t *TxOutput) SerializeToBytes(sl *Serializer)

Jump to

Keyboard shortcuts

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