MultiversXSDK-Go数据结构Skill mvx_sdk_go_data

这个技能涉及MultiversX区块链SDK-Go的核心数据结构和类型,用于定义与区块链交互的核心对象,如交易、地址、账户、网络配置和虚拟机查询。它支持区块链应用开发,包括智能合约、去中心化应用(DApp)和链开发。关键词:MultiversX, 区块链, Go SDK, 数据结构, 智能合约, 链开发, 加密货币, DApp开发, 去中心化应用, 区块链交互。

链开发 0 次安装 0 次浏览 更新于 3/21/2026

name: mvx_sdk_go_data description: MultiversX Go SDK的核心数据结构和类型。

MultiversX SDK-Go 数据结构

这些类型定义了与区块链交互的核心对象。

交易

data.Transaction 是所有网络交互的主要结构。

type Transaction struct {
    Nonce            uint64 `json:"nonce"`
    Value            string `json:"value"`
    RcvAddr          string `json:"receiver"`
    SndAddr          string `json:"sender"`
    GasPrice         uint64 `json:"gasPrice,omitempty"`
    GasLimit         uint64 `json:"gasLimit,omitempty"`
    Data             []byte `json:"data,omitempty"`
    Signature        string `json:"signature,omitempty"`
    ChainID          string `json:"chainID"`
    Version          uint32 `json:"version"`
    Options          uint32 `json:"options,omitempty"`
    Guardian         string `json:"guardian,omitempty"`
    GuardianSignature string `json:"guardianSignature,omitempty"`
    Relayer          string `json:"relayer,omitempty"`
    RelayerSignature string `json:"relayerSignature,omitempty"`
}

地址

type AddressWithType struct {
    address []byte
    hrp     string // "erd" 通常
}

// 方法
// NewAddressFromBech32String(bech32)
// NewAddressFromBytes(bytes)
// AddressAsBech32String()

账户

type Account struct {
    Address         string `json:"address"`
    Nonce           uint64 `json:"nonce"`
    Balance         string `json:"balance"` // BigInt 字符串
    Username        string `json:"username"`
    CodeHash        string `json:"codeHash"`
    RootHash        string `json:"rootHash"`
    DeveloperReward string `json:"developerReward"`
}

网络配置

type NetworkConfig struct {
    ChainID                  string
    MinGasLimit              uint64
    MinGasPrice              uint64
    GasPerDataByte           uint64
    GasPriceModifier         float64
    AdditionalGasForTxSize   uint64
    ...
}

虚拟机查询

type VmValueRequest struct {
    Address    string   `json:"scAddress"`
    FuncName   string   `json:"funcName"`
    CallValue  string   `json:"value"`
    CallerAddr string   `json:"caller"`
    Args       []string `json:"args"` // 十六进制编码的参数
}

type VmValuesResponseData struct {
    ReturnData      []string `json:"returnData"` // 十六进制编码的返回值
    ReturnCode      string   `json:"returnCode"`
    ReturnMessage   string   `json:"returnMessage"`
    GasRemaining    uint64   `json:"gasRemaining"`
    GasRefund       uint64   `json:"gasRefund"`
    OutputAccounts  map[string]*OutputAccount `json:"outputAccounts"`
}

最佳实践

  1. 使用 Value 作为字符串:为了防止溢出(Go 的 int64 对于大额代币量来说太小)。
  2. Bech32 地址:API 期望 bech32 字符串,内部逻辑通常使用字节。
  3. 十六进制编码Data 字段在检查浏览器时经常是十六进制编码的,但 SDK 期望字节/字符串。
  4. 选项位掩码:用于专门的事务(例如,受保护的)。