All Projects → myxtype → filecoin-client

myxtype / filecoin-client

Licence: MIT license
Golang的轻量级filecoin客户端,支持离线签名,基本满足钱包交易所充值提现逻辑

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to filecoin-client

filecoin-box
Filecoin flavored Ganache Truffle box
Stars: ✭ 23 (-54%)
Mutual labels:  ipfs, lotus, filecoin
add-to-web3
⁂ Github Action to upload your website to web3.storage
Stars: ✭ 22 (-56%)
Mutual labels:  ipfs, filecoin
borg
Client-server stack for Web3! Turn your Raspberry Pi to a BAS server in minutes and enjoy the freedom of decentralized Web with a superior user experience!
Stars: ✭ 25 (-50%)
Mutual labels:  ipfs, filecoin
estuary-www
https://estuary.tech
Stars: ✭ 32 (-36%)
Mutual labels:  ipfs, filecoin
nft-website
NFT School: Community education platform for developers in the non-fungible token space.
Stars: ✭ 260 (+420%)
Mutual labels:  ipfs, filecoin
Venus
Filecoin Full Node Implementation in Go
Stars: ✭ 1,901 (+3702%)
Mutual labels:  lotus, filecoin
nft.storage
😋 Free decentralized storage and bandwidth for NFTs on IPFS and Filecoin.
Stars: ✭ 309 (+518%)
Mutual labels:  ipfs, filecoin
lotus-ops
Filecoin cluster deploy ansible playbook and shell scripts.
Stars: ✭ 33 (-34%)
Mutual labels:  lotus, filecoin
valist
Web3-native software distribution. Publish and install executables, Docker images, WebAssembly, and more. Powered by Ethereum, IPFS, and Filecoin.
Stars: ✭ 107 (+114%)
Mutual labels:  ipfs, filecoin
estuary
A custom IPFS/Filecoin node that makes it easy to pin IPFS content and make Filecoin deals.
Stars: ✭ 195 (+290%)
Mutual labels:  ipfs, filecoin
nebula-crawler
🌌 A libp2p DHT crawler, monitor, and measurement tool that exposes timely information about DHT networks.
Stars: ✭ 97 (+94%)
Mutual labels:  ipfs, filecoin
web3.storage
⁂ The simple file storage service for IPFS & Filecoin
Stars: ✭ 417 (+734%)
Mutual labels:  ipfs, filecoin
kotal
Blockchain Kubernetes Operator
Stars: ✭ 137 (+174%)
Mutual labels:  ipfs, filecoin
pop
Run a point-of-presence within Myel, the community powered content delivery network.
Stars: ✭ 28 (-44%)
Mutual labels:  ipfs, filecoin
drpc
drpc is a lightweight, drop-in replacement for gRPC
Stars: ✭ 1,014 (+1928%)
Mutual labels:  rpc
cli
Command Line Interface for @imqueue
Stars: ✭ 20 (-60%)
Mutual labels:  rpc
viddist
[not functional] A completely decentralized alternative to e.g. YouTube
Stars: ✭ 22 (-56%)
Mutual labels:  ipfs
zerorpc-dotnet
A .NET implementation of ZeroRPC
Stars: ✭ 21 (-58%)
Mutual labels:  rpc
S4
S4 is 100% S3 compatible storage, accessed through Tor and distributed using IPFS.
Stars: ✭ 67 (+34%)
Mutual labels:  ipfs
RPC
RPC is a highly available pluggable architecture for remote calls
Stars: ✭ 31 (-38%)
Mutual labels:  rpc

filecoin-client

goproxy.cn

需要自行部署Lotus Node节点:https://lotu.sh/en+getting-started

此库仅添加部分方法,但已经满足钱包充值提现逻辑了,如果需要其他方法,请Fork后自行添加。

充值流程:获取头部高度,从本地高度遍历到头部高度,再根据高度获取区块CID,根据区块CID获取区块的所有消息,判断消息的类型是否0(0为发送Fil),和接收地址是否是本地的地址。

说明请查询client_test文件。

安装

go get github.com/myxtype/filecoin-client

使用

package main

import (
	"context"
	"github.com/filecoin-project/go-address"
	"github.com/myxtype/filecoin-client"
)

func main() {
	client := filecoin.NewClient("http://127.0.0.1:1234/rpc/v0", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.cF__3r_0IR9KwZ2nLkqcBW8vuPePruZieJAVvTAoUA4")

	addr, _ := address.NewFromString("t1e3soclcq34tq7wmykp7xkkmpkzjnghumm3syyay")
	bal, err := client.WalletBalance(context.Background(), addr)
	if err != nil {
		panic(err)
	}

	println(bal.String())
}

离线签名版

公共节点申请:https://infura.io

具体实现逻辑在官方库中:https://github.com/filecoin-project/go-filecoin

package main

import (
	"context"
	"encoding/hex"
	"github.com/filecoin-project/go-address"
	"github.com/filecoin-project/go-state-types/abi"
	"github.com/myxtype/filecoin-client"
	"github.com/myxtype/filecoin-client/local"
	"github.com/myxtype/filecoin-client/types"
	"github.com/shopspring/decimal"
)

func main() {
	// 设置网络类型
	address.CurrentNetwork = address.Mainnet

	// 生产新的地址
	// 新地址有转入fil才激活,不然没法用
	ki, addr, err := local.WalletNew(types.KTSecp256k1)
	if err != nil {
		panic(err)
	}

	println(hex.EncodeToString(ki.PrivateKey))
	println(addr.String())

	// 50a5e6234f5fdfc026bd889347409e11b6ef5b6034a7b0572d7e24ed1e9ba0e4
	// f1dynqskhlixt5eswpff3a72ksprqmeompv3pbesy

	to, _ := address.NewFromString("f1yfi4yslez2hz3ori5grvv3xdo3xkibc4v6xjusy")

	// 转移0.001FIL到f1yfi4yslez2hz3ori5grvv3xdo3xkibc4v6xjusy
	msg := &types.Message{
		Version:    0,
		To:         to,
		From:       *addr,
		Nonce:      0,
		Value:      filecoin.FromFil(decimal.NewFromFloat(0.001)),
		GasLimit:   0,
		GasFeeCap:  abi.NewTokenAmount(10000),
		GasPremium: abi.NewTokenAmount(10000),
		Method:     0,
		Params:     nil,
	}

	client := filecoin.New("https://1lB5G4SmGdSTikOo7l6vYlsktdd:[email protected]")

	// 最大手续费0.0001 FIL
	//maxFee := filecoin.FromFil(decimal.NewFromFloat(0.0001))

	// 估算GasLimit
	//msg, err = client.GasEstimateMessageGas(context.Background(), msg, &types.MessageSendSpec{MaxFee: maxFee}, nil)
	//if err != nil {
	//	panic(err)
	//}

	// 离线签名
	s, err := local.WalletSignMessage(types.KTSecp256k1, ki.PrivateKey, msg)
	if err != nil {
		panic(err)
	}

	println(hex.EncodeToString(s.Signature.Data))
	// 47bcbb167fd9040bd02dba02789bc7bc0463c290db1be9b07065c12a64fb84dc546bef7aedfba789d0d7ce2c4532f8fa0d2dd998985ad3ec1a8b064c26e4625a01

	// 验证签名
	if err := local.WalletVerifyMessage(s); err != nil {
		panic(err)
	}

	mid, err := client.MpoolPush(context.Background(), s)
	if err != nil {
		panic(err)
	}

	println(mid.String())
}

暂时不支持bls类型,仅支持secp256k1,所以离线签名所有类型请选择types.KTSecp256k1

私钥存储在数据库请进行加密存储,建议进行AES加密,将AES密钥放在代码中,别放配置文件,编译到执行文件中。

Util

util.go 中提供FIL小数与大数之间的转换,但没有严格测试,请小心使用。

充值流程

参见:/examples/recharge

Lotus文档

https://lotu.sh/en+api-methods

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].