v2 Contract SDK
  • Orbs Contract SDK
  • Getting Started
    • About smart contracts
    • Becoming a Go developer
    • Installing Gamma - local blockchain
    • Deploying your first contract
    • The Orbs Starter Kit
    • Downloading the Contract SDK
  • Orbs Contracts
    • Smart contracts
    • Layout of a contract file
    • Data types (Exported Functions)
    • State
    • Address
    • Events
    • Error handling
    • Calling other contracts
    • Calling Ethereum contract
    • API Reference
    • Limitations of Orbs Contracts
    • Creating a new contract
  • Gamma in Depth
    • Starting and stopping the server
    • Test keys and accounts
    • Deploying smart contracts
    • Sending transactions and queries
    • Checking sent transaction status
    • Reading Logs from Contracts
    • Working with multiple environments
    • Upgrading to latest versions
    • Gamma server under the hood
    • Deploying Gamma in the Cloud
      • Amazon Web Services
      • Google Cloud Platform
      • Azure
Powered by GitBook
On this page
  1. Orbs Contracts

Events

Orbs contract events give you the ability to log information into the blockchain that is stored as part of the receipt block.

Here is a simple contract that emits an event. We will go over it in details:

package main

import (
    "github.com/orbs-network/orbs-contract-sdk/go/sdk/v1"
    "github.com/orbs-network/orbs-contract-sdk/go/sdk/v1/events"
    "github.com/orbs-network/orbs-contract-sdk/go/sdk/v1/state"
)

var PUBLIC = sdk.Export(giveBirth)
var SYSTEM = sdk.Export(_init)
var EVENTS = sdk.Export(BabyBorn)

func BabyBorn(name string, weight uint32) {}

func _init() {
    state.WriteUint64([]byte("some_data"), 1)
}

func giveBirth(name string) {
    events.EmitEvent(BabyBorn, name, uint32(3))
}

Using the Events API require you first to import it:

import (
    "github.com/orbs-network/orbs-contract-sdk/go/sdk/v1/events"
)

Next, we export the event:

var EVENTS = sdk.Export(BabyBorn)

Then we declare it as an empty function. Note that the empty bracers are required ({}):

func BabyBorn(name string, weight uint32) {}

When the function giveBirth(name string) is called, we want the event to be emitted, so we call the events.EmitEvent function:

events.EmitEvent(BabyBorn, name, uint32(3))

The arguments are a pointer to the event function (which is also exported) and the event arguments.

PreviousAddressNextError handling

Last updated 5 years ago