filecoin

package module
v0.0.0-...-c4e539a Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 20 Imported by: 0

README

filecoin-sdk

Filecoin SDK is used to interact with the Filecoin 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/xiaohuasheng0x1/blockchains/coins/filecoin

Usage

New Address
	privateKeyHex := "0x7c6207c56b6aa5ed4345c5f662816408e273cbdf64e2f01d54ced0125d6172c2"
	address, err := GetAddressByPrivateKey(privateKeyHex, MainnetPrefix)
	if err != nil {
		// todo
	}
Transfer
	from := "f1bh3d2y6xxugpg3ygzxnjhcrs5ffxh5nvqmanbia"
	to := "f1fvs2fjqr6ozk477zkwzvermhledmfkswt34cmhi"
	nonce := 0
	value := big.NewInt(20000000000000000)
	gasLimit := 210000
	gasFeeCap := big.NewInt(9455791480)
	gasPremium := big.NewInt(120242)
	method := 0
	message := NewTx(from, to, nonce, method, gasLimit, value, gasFeeCap, gasPremium)
	privateKeyHex := "0x7c6207c56b6aa5ed4345c5f662816408e273cbdf64e2f01d54ced0125d6172c2"
	tx, err := SignTx(message, privateKeyHex)
	if err != nil {
		// todo
	}

License

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

Documentation

Index

Constants

View Source
const (
	MainnetPrefix = "f"
	TestnetPrefix = "t"
)
View Source
const (
	ID byte = iota
	SECP256K1
	Actor
	BLS
)

Variables

View Source
var (
	AddressEncoding = base32.NewEncoding(encodeStd)
)

Functions

func AddressToBytes

func AddressToBytes(addr string) []byte

func GetAddressByPrivateKey

func GetAddressByPrivateKey(privateKeyHex string, chainId string) (string, error)

func GetAddressByPublicKey

func GetAddressByPublicKey(publicKeyHex string, chainId string) (string, error)

func GetPublicKey

func GetPublicKey(privateKeyHex string) (string, error)

func NewPrivateKey

func NewPrivateKey() string

func SignedTx

func SignedTx(message *Message, signHex string) (string, error)

Types

type BigInt

type BigInt big.Int

func (BigInt) Bytes

func (bn BigInt) Bytes() []byte

func (BigInt) MarshalJSON

func (bn BigInt) MarshalJSON() ([]byte, error)

type Message

type Message struct {
	Version    uint64  `json:"Version"`
	To         string  `json:"To"`
	From       string  `json:"From"`
	Nonce      uint64  `json:"Nonce"`
	Value      *BigInt `json:"Value"`
	GasLimit   int64   `json:"GasLimit"`
	GasFeeCap  *BigInt `json:"GasFeeCap"`
	GasPremium *BigInt `json:"GasPremium"`
	Method     uint64  `json:"Method"`
	Params     []byte  `json:"Params"`
}

func NewTx

func NewTx(from, to string, nonce, method, gasLimit int, value, gasFeeCap, gasPremium *big.Int) *Message

func (*Message) Hash

func (m *Message) Hash() []byte

func (*Message) Serialize

func (m *Message) Serialize() []byte

type Signature

type Signature struct {
	Type byte
	Data []byte
}

type SignedMessage

type SignedMessage struct {
	Message   *Message  `json:"Message"`
	Signature Signature `json:"Signature"`
}

func SignTx

func SignTx(message *Message, privateKeyHex string) (*SignedMessage, error)

Jump to

Keyboard shortcuts

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