> For the complete documentation index, see [llms.txt](https://docs.orbs.network/v2-contract-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.orbs.network/v2-contract-sdk/orbs-contracts/smart-contracts.md).

# Smart contracts

Smart contracts are the cornerstone of decentralized systems. When developers are building a decentralized app, they are implementing one or more smart contracts, and ultimately deploying them to run over a blockchain infrastructure like Orbs.

## Orbs smart contracts

The Orbs smart contracts are the logic of your apps: the high level workflow is creating the contracts (code) using the Orbs Contract SDK, testing it and experimenting with the Gamma framework, and later deploying your contract to the Orbs blockchain.

Currently, the contracts can be written in the Golang language. In the future the Orbs contract SDK will be available in other languages as well.

Similar to other Smart Contract frameworks, an Orbs contract is comprised of the written code (functions) and data (state) that resides inside of the blockchain.

Here is an example of a straightforward contract that implements a counter. It has two main functions, `get` and `add`, and it stores a single state value called `counter`.

{% code title="counter.go" %}

```go
package main

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

var PUBLIC = sdk.Export(add, get)
var SYSTEM = sdk.Export(_init)

var COUNTER_KEY = []byte("count")

func _init() {
    state.WriteUint64(COUNTER_KEY, 0)
}

func add(amount uint64) {
    count := state.ReadUint64(COUNTER_KEY)
    count += amount
    state.WriteUint64(COUNTER_KEY, count)
}

func get() uint64 {
    return state.ReadUint64(COUNTER_KEY)
}
```

{% endcode %}

## Storage and State

The line `state.WriteUint64([]byte("count"), 0)` will use the `state` library to write to the state. The state library is the only way to interact with the contract state and thus non-volatile storage. In the `get()` function, the line `return state.ReadUint64([]byte("count"))` will read the `count` value (and return it), that `count` value is the same one that was written in the `_init()` function or the `add()` function.

The state is described in more detail at the [Contract state](https://orbs.gitbook.io/contract-sdk/~/edit/drafts/-LVnlbSBlfPGStLbU5Xx/orbs-contracts/contract-state) documentation page.

## Exported functions

In Golang, functions beginning with the lowercase letters are considered as 'private' or not exported, and those whose name starts with an uppercase are 'public' and exported.

In Orbs, all functions should be written as 'private', meaning beginning with a lowercase letter, and functions that should be exported will be declared explicitly using the `sdk.Export()` function. In the example above, we can see that the functions `add` and `get` are declared as exported.

## Transactions and Queries

There are two ways of interacting with the Orbs blockchain: sending a **transaction** or running a **query**.

Sending a **transaction** means that the logic executed by the contract inside the virtual machine is executed under consensus, and thus the logic is **allowed** to change the state.

Running a **query** is a more lightweight operation which does not happen under consensus. However, if the logic of the querry is executed and the state is being written to, the result of the execution will be an **error**, as the operation was not done under a transaction.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.orbs.network/v2-contract-sdk/orbs-contracts/smart-contracts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
