Go Smart Contract Development Kit
Project description
Go Smart Contracts Development Kit
What a Go Smart Contract looks like?
Here is an example
package main
import (
"github.com/uuosio/chain"
)
//table mytable
type MyData struct {
primary uint64 //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
payer := c.Receiver
mydb := NewMyDataDB(code)
primary := uint64(111)
if it, data := mydb.GetByKey(primary); it.IsOk() {
if data.name != name {
chain.Println("Welcome new friend:", name)
} else {
chain.Println("Welcome old friend", name)
}
data.name = name
mydb.Update(it, data, payer)
} else {
chain.Println("Welcome new friend", name)
data := &MyData{primary, name}
mydb.Store(data, payer)
}
}
Quick Start
Installation
python3 -m pip install gscdk
For the Windows platform:
python -m pip install gscdk
Upgrade From an Old Version
python3 -m pip install --upgrade gscdk
For the Windows platform:
python -m pip install --upgrade gscdk
Building Go Smart Contracts Compiler
Follow the steps in Building
That will build the tinygo
command in the compiler/build directory that supports building Go Smart Contracts.
export PATH=$(pwd)/compiler/build:$PATH
go-contract
Initializing a project with the "init" subcommand
The "init" command initializes a project with the contract name
go-contract init mycontract
cd mycontract
Generating ABI and Extra Code for Smart Contracts
go-contract gencode
Code generation is also the default option for the "build" command
Building Go Smart Contracts Project
Compiling the Source Code
go-contract build
Disable Code Generation during Building
go-contract build -gen-code=false .
Disable Code Optimization
Specifying -d
or --debug
option to disable wasm optimization.
go-contract build -d
Debugging
Install ipyeos
first for debugging.
python3 -m pip install ipyeos
In order to update to a new version, use the following command:
python3 -m pip install -U ipyeos
Then run the debugging server:
eosdebugger
On Windows, you need to use a docker image to run a debugging server.
docker pull ghcr.io/uuosio/ipyeos:latest
Run the debugging server on the Windows platform:
docker run -it --rm -p 9090:9090 -p 9092:9092 -t ghcr.io/uuosio/ipyeos
Code Coverage Analysis
Use the following command to generate a code coverage report in html
go-contract build
TEST_COVERAGE=1 go test -coverprofile=coverage.out
go tool cover -html=coverage.out
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for gscdk-0.7.8-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77f17f2cbb670ba482edb94d75c8e87dab31afadf17cdc1eae0d833eb21cbc54 |
|
MD5 | acf07984b73f1ecb823a4a32585e9a9c |
|
BLAKE2b-256 | f070c4ff0d49122b054b50a9a617bdbac1ee1896f141d36589c179bc7565bf34 |
Hashes for gscdk-0.7.8-py3-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8de5ec4709ac0744cb2004f8b0ea7a2782626e7508236f424db973bec33e70d |
|
MD5 | 3650856b85477b945b131ad3c4f63a7d |
|
BLAKE2b-256 | 77c21efa37a3d6485494c875e5aa863154eaf5c1f246342fc9523f7c6dee3162 |
Hashes for gscdk-0.7.8-py3-none-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ceb2d0ac0cc9b01a74eedfac028c6c1f7fcab9b0d5ffd35b6da1e17b20bdc703 |
|
MD5 | 376a6a9e5938376853fc5abca5c8610f |
|
BLAKE2b-256 | 1475b3776a208c604cad15f98b20742b1a2db5c13cc784e6078c1cb44b20f05c |