# Compiling a smart contract in Golang (Go)

When compiling a Go contract one wants to reduce the resulting binary size to the bare minimum possible to save on deployment fees, since that metric is tied only to the size of the deployed binary.

As a good rule of thumb is to always strip DWARF, symbol table and debug info. To achieve that build with the following flags like the below example:

```
go build -ldflags '-s -w'
```

We will provide an optimized compiler for Go which will shrink the binary size (and as a result the deployment fees!) by an order of magnitude. The sample provided compiles to a \~200k sized binary instead of \~1.3M one with information stripped as recommended above or \~1.8M without removing those!

## Compiling with the QVM compiler <a href="#compiling-with-the-qvm-compiler" id="compiling-with-the-qvm-compiler"></a>

We already supply a simple compiler container which adds the suggested flags described above to the build command. Since you saved the previous sample contract as `main.go` in your current directory, you can run the compiler like this:

```
docker run --rm -v $(pwd):/ws qanplatform/qvm-compiler-go
```

Afterwards you will end up with a statically linked linux ELF binary called `"contract"` in your current directory.


---

# Agent Instructions: 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://learn.qanplatform.com/developers/qvm-multi-language-smart-contracts/docs-for-supported-languages/golang-go-smart-contract/compiling-a-smart-contract-in-golang-go.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.
