Quick Start

Install

go get github.com/yu-org/yu

Develop an on-chain Writing and Reading

import (
	"github.com/yu-org/yu/apps/pow"
	. "github.com/yu-org/yu/core/types"
	"github.com/yu-org/yu/env"
	"github.com/yu-org/yu/common"
	"github.com/yu-org/yu/context"
	"github.com/yu-org/yu/startup"
	"github.com/yu-org/yu/tripod"
)

type Example struct {
	*tripod.Tripod
}

// Here is a custom development of a Writing.   
// The Writing will be consensus and executed across the entire network.
func (e *Example) WriteA(ctx *context.WriteContext) error {
	caller := ctx.GetCaller()
	// set this Writing lei cost (lei and gas are synonymous)
	ctx.SetLei(100) 
	// Store data in on-chain state.
	e.Set(caller.Bytes(), []byte("yu")) 
	// Emit an event.
	ctx.EmitStringEvent("execute success")
	return nil
}

// Here is a custom development of a Reading
func (e *Example) ReadA(ctx *context.ReadContext) {
    key := ctx.GetString("key")
    value, err := e.Get(key.Bytes())
    if err != nil {
		ctx.JsonOk(err)
		return
    }
    ctx.JsonOk(string(value))
}

Add tripods in the main function

func NewExample() *Example {
	df := tripod.NewTripod()
	e := &Example{df}

	// Here you need to manually register the custom Writing to tripod,
	e.SetWritings(e.WriteA)
	// Here you need to manually register the custom Reading into tripod
	e.SetReadings(e.ReadA)

	return e
}

func main() {
	poaConf := poa.DefaultCfg(0)
	startup.InitDefaultKernelConfig()
	startup.DefaultStartup(poa.NewPoa(poaConf), NewExample())
}

Run

go build -o yu-poa-example

./yu-poa-example  
 

At this point, a blockchain has been activated. In the future, more blockchain nodes can be added to build a blockchain network