Skip to main content

Go Smart Contract Development Kit

Project description

Go Smart Contracts Development Kit

Quick Start

Quick Start Binder

What the Go Smart Contracts look like?

Here is an example

package main

import (
    "github.com/uuosio/chain"
    "github.com/uuosio/chain/logger"
)

//table mytable
type MyData struct {
    primary uint64 //primary: t.primary
    name    string
}

//contract mycontract
type MyContract struct {
    Receiver      chain.Name
    FirstReceiver chain.Name
    Action        chain.Name
}

func NewContract(receiver, firstReceiver, action chain.Name) *MyContract {
    return &MyContract{receiver, firstReceiver, action}
}

//action sayhello
func (c *MyContract) SayHello(name string) {
    code := c.Receiver
    scope := code
    payer := c.Receiver
    mydb := NewMyDataDB(code, scope)
    primary := uint64(111)
    if it, data := mydb.Get(primary); it.IsOk() {
        if data.name != name {
            logger.Println("Welcome new friend:", name)
        } else {
            logger.Println("Welcome old friend", name)
        }
        data.name = name
        mydb.Update(it, data, payer)
    } else {
        logger.Println("Welcome new friend", name)
        data := &MyData{primary, name}
        mydb.Store(data, payer)
    }
}

Installation

pip install gscdk

Build Go Smart Contracts Compiler

Follow the steps in Building

That will build tinygo command in compiler/build directory that support for building Go Smart Contracts.

Set PATH

export PATH=$(pwd)/compiler/build:$PATH

Install from Pre-built Binary

First download binary file from releases

For tar.gz file

tar -C /usr/local -xzf uuosio.gscdk-linux-0.1.0.tar.gz
export PATH=/usr/local/uuosio.gscdk/bin:$PATH

Install through a Python wheel package

python3 -m pip install https://github.com/uuosio/uuosio.gscdk/releases/download/v0.1.2/gscdk-0.1.0-py3-none-manylinux1_x86_64.whl

Change the wheel package download url as you need.

Install debian package directly on Ubuntu platform

sudo apt install ./uuosio.gscdk-linux-0.1.0.deb

eosio-go Command

Init Command

Init command initialize a project with contract name

eosio-go init mycontract
cd mycontract

Generating ABI and Extra Code for Smart Contracts

eosio-go gencode

Code generation is also the default option for "build" command

Build Command

Compile Source Code

eosio-go build -o mycontract.wasm .

Disable Code Generation during Building

eosio-go build -gen-code=false -o mycontract .

Disable Striping WASM File after Building

eosio-go build -strip=false -o mycontract .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gscdk-0.2.0.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distributions

gscdk-0.2.0-py3-none-win_amd64.whl (53.5 MB view hashes)

Uploaded Python 3 Windows x86-64

gscdk-0.2.0-py3-none-manylinux1_x86_64.whl (57.2 MB view hashes)

Uploaded Python 3

gscdk-0.2.0-py3-none-macosx_10_15_x86_64.whl (49.3 MB view hashes)

Uploaded Python 3 macOS 10.15+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page