home / skills / multiversx / mx-ai-skills / mvx_sdk_go_core

mvx_sdk_go_core skill

/antigravity/skills/mvx_sdk_go_core

This skill enables efficient blockchain data access with the MultiversX Go SDK core, covering proxy setup, VM queries, and shard coordination.

npx playbooks add skill multiversx/mx-ai-skills --skill mvx_sdk_go_core

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.0 KB
---
name: mvx_sdk_go_core
description: Core network operations for MultiversX Go SDK - Proxy, VM Queries.
---

# MultiversX SDK-Go Core Operations

This skill covers the `blockchain` package and network interactions.

## Proxy (Network Client)

Setup the proxy to interact with the blockchain:

```go
import (
    "github.com/multiversx/mx-sdk-go/blockchain"
    "github.com/multiversx/mx-sdk-go/core/http"
)

// Configure Proxy
args := blockchain.ArgsProxy{
    ProxyURL:            "https://devnet-gateway.multiversx.com",
    Client:              http.NewHttpClientWrapper(nil, ""),
    SameScState:         false,
    ShouldBeSynced:      false,
    FinalityCheck:       false,
    CacheExpirationTime: time.Minute,
    EntityType:          core.Proxy,
}

proxy, err := blockchain.NewProxy(args)
```

## Reading Data

```go
// Get Account
address := data.NewAddressFromBech32String("erd1...")
account, err := proxy.GetAccount(ctx, address)
// account.Nonce, account.Balance

// Get Network Config
config, err := proxy.GetNetworkConfig(ctx)

// Get Transaction
tx, err := proxy.GetTransaction(ctx, "txHash", true)
```

## VM Queries (Smart Contract Reads)

Reading state from a smart contract without sending a transaction.

```go
argsQuery := blockchain.ArgsVmQueryGetter{
    Proxy:   proxy,
    Timeout: 10 * time.Second,
}
vmQueryGetter, err := blockchain.NewVmQueryGetter(argsQuery)

// Execute Query
response, err := vmQueryGetter.ExecuteQueryReturningBytes(
    contractAddress,
    "getFunctionName",
    [][]byte{arg1, arg2}, // Arguments as byte slices
)

// response is [][]byte
```

## Shard Coordination

Working with sharded addresses.

```go
// Create Coordinator
coordinator, err := blockchain.NewShardCoordinator(3, 0) // 3 shards, current 0

// Get Shard for Address
shardID := coordinator.ComputeId(address)
```

## Best Practices

1. **Reuse Proxy**: It maintains connection pools/caches
2. **Context**: Always pass context with timeout to avoid hanging
3. **VM Queries**: Preferred for reading state (instant, free)
4. **Error Handling**: Check for specific network errors

Overview

This skill explains core network operations for the MultiversX Go SDK, focusing on proxy client setup, VM queries, and shard coordination. It summarizes how to create and reuse a proxy, perform smart contract read queries, and compute shard IDs for addresses. The guidance highlights practical workflows and safety considerations for reliable network interactions.

How this skill works

You configure a Proxy client that wraps HTTP connections, caching, and sync checks to interact with gateway endpoints. For reading smart contract state, the VmQueryGetter executes queries via the proxy and returns raw byte responses without creating transactions. A ShardCoordinator maps addresses to shard IDs so you can route requests or partition logic across shards.

When to use it

  • When you need to read account, network, or transaction data from a MultiversX gateway.
  • When you want to read smart contract state without submitting a transaction (free, instant reads).
  • When building services that must reuse HTTP connections and caches for efficiency.
  • When you must determine shard placement for addresses or shard-aware request routing.
  • When you need reliable timeouts and context-aware network calls to avoid hangs.

Best practices

  • Create and reuse a single Proxy instance to leverage connection pooling and caching.
  • Always pass a context with timeouts for proxy calls and VM queries to prevent indefinite waits.
  • Prefer VM queries for reads to avoid gas costs and transaction latency.
  • Handle network errors explicitly and implement retry/backoff for transient failures.
  • Cache stable results (like network config) and respect cache expiration to reduce gateway load.

Example use cases

  • A backend service fetching user account nonces and balances before building transactions.
  • A dashboard performing contract state reads (via VM queries) to display real-time info.
  • A microservice that routes requests to shard-specific workers using shard IDs.
  • A CLI tool that fetches transaction details and network configuration for diagnostics.
  • Automated monitoring that polls gateway endpoints with timeouts and controlled retries.

FAQ

Do VM queries cost gas or require signing?

No. VM queries read contract state via the gateway and do not create on-chain transactions, so they do not consume gas or require signing.

Should I create a new Proxy for each request?

No. Reuse a single Proxy instance to benefit from connection pooling, caching, and reduced resource use.