filecoin

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: MIT Imports: 21 Imported by: 0

README

filecoin-sdk

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

Installation

go get

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

go get -u github.com/724165435/go-wallet-sdk/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
	}
    hash, err := CalTxHash(tx)
    if err != nil {
        // todo
    }

Credits This project includes code adapted from the following sources:

  • lotus - Filecoin Go SDK

If you are the original author and would like credit adjusted, please contact us.

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"

	// MaxInt64StringLength defines the maximum length of `int64` as a string.
	MaxInt64StringLength = 19

	// ChecksumHashLength defines the hash length used for calculating address checksums.
	ChecksumHashLength = 4

	// MaxSubaddressLen is the maximum length of a delegated address's sub-address.
	MaxSubaddressLen = 54
)
View Source
const (
	ID byte = iota
	SECP256K1
	Actor
	BLS
	Delegated
)

Variables

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

Functions

func AddressToBytes

func AddressToBytes(addr string) []byte

func CalTxHash

func CalTxHash(tx string) (string, error)

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)

func (*BigInt) UnmarshalJSON

func (bn *BigInt) UnmarshalJSON(data []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" cbor:"omitempty"`
}

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)

func (*SignedMessage) Hash

func (sm *SignedMessage) Hash() string

func (*SignedMessage) Serialize

func (sm *SignedMessage) Serialize() []byte

Jump to

Keyboard shortcuts

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