home / skills / multiversx / mx-ai-skills / mvx_sdk_go_builders
This skill helps you construct and sign transactions in Go SDK using builders, ensuring correct fields, signing, and ready-to-submit payloads.
npx playbooks add skill multiversx/mx-ai-skills --skill mvx_sdk_go_buildersReview the files below or copy the command above to add this skill to your agents.
---
name: mvx_sdk_go_builders
description: Transaction construction and signing using Builders in Go SDK.
---
# MultiversX SDK-Go Builders
Using `TxBuilder` to construct and sign transactions.
## Transaction Builder
```go
import (
"github.com/multiversx/mx-sdk-go/builders"
"github.com/multiversx/mx-sdk-go/core"
"github.com/multiversx/mx-sdk-go/data"
)
// Initialize
txBuilder, err := builders.NewTxBuilder(core.Marshalizer)
// Manual Transaction Construction
tx := &data.Transaction{
Nonce: nonce,
Value: "1000000000000000000", // 1 EGLD
RcvAddr: receiverAddressString,
SndAddr: senderAddressString,
GasPrice: 1000000000,
GasLimit: 50000,
Data: []byte("memo"),
ChainID: "D",
Version: 1,
}
// Sign Transaction
err = txBuilder.ApplySignature(tx, privateKey)
// tx.Signature, tx.SenderUsername are updated
```
## Contract Builders (High Level)
There are specific builders for SC interactions (often generated code or custom implementations), but the core pattern is:
1. Create `data.Transaction` struct
2. Populate fields (Date = endpoint@arg1@arg2)
3. Sign with `TxBuilder`
## Token Transfers
ESDT transfers require specific data fields.
```go
// Native EGLD
tx.Value = "1000000000000000000"
tx.Data = []byte("")
// ESDT Transfer
// Function: ESDTTransfer
// Args: TokenIdentifier (hex), Amount (hex)
tx.Value = "0"
tx.Data = []byte("ESDTTransfer@" + hexTokenId + "@" + hexAmount)
```
## Relayed V3 Transactions
Constructing the inner transaction for a relayed call.
```go
// Inner Tx (User)
innerTx := &data.Transaction{...}
// Sign Inner Tx
signature, _ := userPrivateKey.Sign(innerTxBytes)
// Relayer Tx
relayerTx := &data.Transaction{
Sender: relayerAddress,
Data: []byte("relayedTx@" + innerTxBytesHex + "@" + signatureHex),
...
}
```
## Data Serialization
The SDK uses a `Marshalizer` interface (usually JSON).
```go
import "github.com/multiversx/mx-sdk-go/core"
bytes, err := core.Marshalizer.Marshal(tx)
```
## Best Practices
1. **Validate fields** before building
2. **Use correct ChainID** ('1', 'D', 'T')
3. **Handle Big Ints as strings** in `Value` field
4. **Gas Limit estimation** is manual or via proxy simulation
This skill demonstrates how to construct, sign, and prepare transactions using the MultiversX Go SDK builders. It focuses on the TxBuilder pattern, manual transaction creation, contract interaction payloads, token transfers (native and ESDT), relayed transactions, and serialization. The goal is to get developers from raw fields to a signed transaction ready for broadcast.
You create a data.Transaction object, populate canonical fields (Nonce, Value, Sender, Receiver, GasPrice, GasLimit, Data, ChainID, Version), then use TxBuilder.ApplySignature to attach the sender signature and derived sender metadata. For contract calls and ESDT transfers the Data field encodes function name and hex-encoded args (e.g., "ESDTTransfer@<tokenHex>@<amountHex>"). For relayed flows you sign an inner user transaction, embed its bytes and signature into a relayer transaction Data payload, then the relayer publishes it.
How should I represent large token amounts?
Represent large amounts as decimal strings in Value or hex-encoded strings for ESDT arguments to avoid integer overflow.
How do I sign a relayed transaction?
Sign the inner user transaction bytes to get a signature, then embed innerTxBytesHex and signatureHex into relayerTx.Data as the relayed payload before the relayer signs.