> For the complete documentation index, see [llms.txt](https://docs.zama.org/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/protocol/sdk/getting-started/go-quick-start.md).

# Go quick start

Encrypt a first confidential contract input from Go with the Zama SDK daemon.

{% hint style="warning" %}
The daemon and its Go and Rust clients are experimental. The wire protocol can change between minor versions, so upgrade the daemon image and the clients together.
{% endhint %}

We'll encrypt `1000` as an `euint64` for a confidential contract on Sepolia and print the encrypted value and the size of its input proof. You don't sign or broadcast anything.

The Go client talks to a local SDK daemon over a private Unix socket. The daemon runs the Zama SDK, so your application stays in Go.

You need Go 1.26 or later, Docker Compose on Linux or Docker Desktop, a Sepolia RPC URL, the address of your confidential contract, and the address of the user who will submit the input.

## Authentication

The Sepolia testnet relayer needs no API key, so this quick start leaves authentication unset. The Zama-hosted mainnet relayer requires a key. When you move to mainnet, set it on the SDK configuration:

```go
config := zama.NewSDKConfig(1, rpcURL)
config.Auth = zama.APIKeyHeader{Value: os.Getenv("RELAYER_API_KEY")}
```

See [Authentication](https://docs.zama.org/protocol/sdk/guides/authentication.md) and [Relayer API keys](https://docs.zama.org/protocol/sdk/guides/relayer-api-keys.md) to get a key and keep it out of your logs.

## Install

Create a module and add the client:

```sh
export ZAMA_SDK_VERSION=3.8.0
mkdir encrypt-input
cd encrypt-input
go mod init example.com/encrypt-input
go get github.com/zama-ai/sdk/clients/go/v3@v$ZAMA_SDK_VERSION
```

`ZAMA_SDK_VERSION` pins the client here and the daemon image that Compose starts later: both must run the same version. See [Client and daemon compatibility](https://docs.zama.org/protocol/sdk/api-references/client-and-daemon-compatibility.md).

## Set up the SDK

Download the daemon's [Compose file](https://docs.zama.org/protocol/sdk/go-and-rust-guide/operations/run-in-production.md#run-with-docker-compose):

```sh
curl -fsSL -o zama-sdk-daemon.yaml "https://raw.githubusercontent.com/zama-ai/sdk/v${ZAMA_SDK_VERSION}/packages/sdk-daemon/deploy/compose.yaml"
```

Save this as `compose.yaml`. It runs your program in a Go container next to the daemon. Both run as UID 10000 and GID 10001, the daemon image's user, and share the daemon's socket volume:

```yaml
include:
  - zama-sdk-daemon.yaml

services:
  app:
    image: golang:1.26
    user: "10000:10001"
    working_dir: /src
    environment:
      - DAEMON_SOCKET=/run/zama/sdk.sock
      - GOCACHE=/tmp/go-cache
      - GOMODCACHE=/tmp/go-mod
      - SEPOLIA_RPC_URL
      - CONTRACT_ADDRESS
      - USER_ADDRESS
    volumes:
      - .:/src:ro
      - socket:/run/zama:ro
    depends_on:
      daemon:
        condition: service_healthy
    command: ["go", "run", "."]
```

The daemon needs outbound access to your RPC endpoint and to the Sepolia relayer. Your application connects with `zama.Dial` and creates an SDK context from a chain configuration. The SDK context lives in the daemon until you close it.

## Your first encrypted input

Save this file as `main.go`:

```go
package main

import (
	"context"
	"fmt"
	"math/big"
	"os"
	"time"

	"github.com/ethereum/go-ethereum/common"
	zama "github.com/zama-ai/sdk/clients/go/v3"
)

func run() error {
	socket := os.Getenv("DAEMON_SOCKET")
	rpcURL := os.Getenv("SEPOLIA_RPC_URL")
	contract := os.Getenv("CONTRACT_ADDRESS")
	user := os.Getenv("USER_ADDRESS")
	if socket == "" || rpcURL == "" || !common.IsHexAddress(contract) || !common.IsHexAddress(user) {
		return fmt.Errorf("set DAEMON_SOCKET, SEPOLIA_RPC_URL, CONTRACT_ADDRESS and USER_ADDRESS")
	}

	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()

	client, err := zama.Dial(socket)
	if err != nil {
		return err
	}
	defer client.Close()

	sdk, err := client.CreateContext(ctx, zama.NewSDKConfig(11155111, rpcURL), zama.SignerConfig{})
	if err != nil {
		return err
	}
	defer func() {
		cleanup, cancel := context.WithTimeout(context.Background(), 5*time.Second)
		defer cancel()
		if err := sdk.Close(cleanup); err != nil {
			fmt.Fprintln(os.Stderr, "close SDK context:", err)
		}
	}()

	result, err := sdk.Encrypt(ctx, zama.EncryptParams{
		Values:          []zama.EncryptInput{zama.Euint64(big.NewInt(1000))},
		ContractAddress: common.HexToAddress(contract),
		UserAddress:     common.HexToAddress(user),
	}, zama.EncryptOptions{})
	if err != nil {
		return err
	}

	fmt.Println("Encrypted value:", result.EncryptedValues[0].Hex())
	fmt.Printf("Input proof: %d bytes\n", len(result.InputProof))
	return nil
}

func main() {
	if err := run(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
```

Set your values and run it:

```sh
export SEPOLIA_RPC_URL=https://your-sepolia-rpc.example
export CONTRACT_ADDRESS=0xYourConfidentialContract
export USER_ADDRESS=0xYourUserAddress
go mod tidy
docker compose run --rm app
```

`docker compose run` starts the daemon, waits for its healthcheck, then runs the program. It prints one encrypted value and a nonzero proof size. Pass both to your confidential contract call. They change on every run.

When you're done, stop the daemon. Add `-v` to also delete its volumes, including stored credentials:

```sh
docker compose down
```

## Next steps

* [Configuration](https://docs.zama.org/protocol/sdk/guides/configuration.md) -- chains, relayers, provider options, storage, and the daemon connection
* [Encrypt & decrypt](https://docs.zama.org/protocol/sdk/guides/encrypt-decrypt.md) -- submit encrypted inputs and decrypt contract results
* [Attach a wallet](https://docs.zama.org/protocol/sdk/go-and-rust-guide/guides/attach-wallet.md) -- signatures for private decryption and transaction writes
* [Go client API](https://docs.zama.org/protocol/sdk/api-references/go-client.md) -- generated package reference
* [Deploy in production](https://docs.zama.org/protocol/sdk/go-and-rust-guide/operations/run-in-production.md) -- run the daemon on your infrastructure


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/protocol/sdk/getting-started/go-quick-start.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
