ckb-rich-sdk-go

command module
v0.1.7-0...-f014df5 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2020 License: MIT Imports: 7 Imported by: 0

README

ckb-rich-sdk-go

License Go version Telegram Group

Golang SDK for Nervos rich node.

Demos

package main

import (
	"context"
	"encoding/hex"
	"fmt"
	"log"

	"github.com/shaojunda/ckb-rich-sdk-go/indexer"
	"github.com/shaojunda/ckb-rich-sdk-go/rpc"
	"github.com/nervosnetwork/ckb-sdk-go/types"
)

func main() {
	c, err := rpc.Dial("http://localhost:8117/rpc", "http://localhost:8117/indexer")
	if err != nil {
		log.Fatalf("dial rpc error: %v", err)
	}

	blockNumber, _ := c.GetTipBlockNumber(context.Background())
	fmt.Println(blockNumber)

	args, _ := hex.DecodeString("c2baa1d5b45a3ad6452b9c98ad8e2cc52e5123c7")
	searchKey := &indexer.SearchKey{
		Script: &types.Script{
			CodeHash: types.HexToHash("0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"),
			HashType: types.HashTypeType,
			Args:     args,
		},
		ScriptType: indexer.ScriptTypeLock,
	}

	// first page
	liveCells, _ := c.GetCells(context.Background(), searchKey, indexer.SearchOrderAsc, 100, "")

	fmt.Println(liveCells.LastCursor)
	fmt.Println(len(liveCells.Objects))
	fmt.Println(liveCells.Objects[0].OutPoint.TxHash)
	fmt.Println(liveCells.Objects[0].OutPoint.Index)

	// search next page
	liveCells, _ = c.GetCells(context.Background(), searchKey, indexer.SearchOrderAsc, 100, liveCells.LastCursor)
	fmt.Println(liveCells.LastCursor)
	fmt.Println(len(liveCells.Objects))
	fmt.Println(liveCells.Objects[0].OutPoint.TxHash)
	fmt.Println(liveCells.Objects[0].OutPoint.Index)

	fmt.Println("-------------------------------------")
	transactions, _ := c.GetTransactions(context.Background(), searchKey, indexer.SearchOrderAsc, 100, "")
	fmt.Println(transactions.LastCursor)
	fmt.Println(len(transactions.Objects))
	fmt.Println(transactions.Objects[0].TxHash)
	fmt.Println(transactions.Objects[0].IoType)
	transactions, _ = c.GetTransactions(context.Background(), searchKey, indexer.SearchOrderAsc, 100, transactions.LastCursor)
	fmt.Println(transactions.LastCursor)
	fmt.Println(len(transactions.Objects))
	fmt.Println(transactions.Objects[0].TxHash)
	fmt.Println(transactions.Objects[0].IoType)
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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