Skip to content

Go SDK Carbon API And Wire Format

pkg/carbon contains Carbon serialization primitives, typed wire structures, transaction payloads, schema helpers, fee helpers, token lifecycle builders, signing helpers, and result parsers.

Core Serialization

APIPurpose
NewWriter() / WriterWrites Carbon primitives and arrays.
NewReader(data) / ReaderReads Carbon primitives and arrays with bounds checks.
BlobThe interface of every Carbon structure: WriteCarbon(*Writer) and ReadCarbon(*Reader).
Serialize(blob)Serializes a complete Blob.
Deserialize(data, blob)Parses one complete blob into the supplied value. It returns an error for input that is cut short or has bytes left over.
DecodeHex(text)Hex to bytes, with or without 0x.
Bytes16, Bytes32, Bytes64Fixed-width byte values with checked constructors (NewBytes32, Bytes32FromHex) and Bytes(), String().
SmallStringA UTF-8 string of at most 255 bytes with a one-byte length.
IntXCarbon variable-width signed integer: NewIntX, IntXFromInt64, MustIntXFromString, BigInt(), Is8ByteSafe().
Bytes32FromPublicKey, Bytes32FromPhantasmaAddress, Bytes32FromPhantasmaAddressTextAccount and address conversion helpers for Carbon messages.
SystemAddressNull, SystemAddressGasPool, SystemAddressDataPoolFixed system accounts.

Must... helpers panic. Use them for constants and test vectors, not for user input.

Reader.ReadLengthFor(elementSize) rejects non-positive element sizes, negative Carbon array lengths, and fixed-width array lengths whose required bytes exceed the remaining input before allocating the result slice.

Writer And Reader Methods

GroupWriter methodsReader methods
Fixed integersWrite1, Write2, Write4, Write4U, Write8, Write8URead1, Read2, Read4, Read4U, Read8, Read8U
Fixed bytesWrite16, Write32, Write64Read16, Read32, Read64
Big integersWriteBigInt, WriteBigIntArrayReadBigInt, ReadBigIntArray
Strings and bytesWriteStringZ, WriteStringZArray, WriteByteArray, WriteByteArraysReadStringZ, ReadStringZArray, ReadByteArray, ReadByteArrays
Integer arraysWriteInt8Array, WriteInt16Array, WriteInt32Array, WriteInt64Array, WriteUint64Arraymatching Read...Array methods
StructuresWriteBlob, WriteBlobArray, WriteRaw, WriteFixedReadRaw, ReadLength, ReadLengthFor, AssertEOF

Wire Layout

All integers are little-endian.

ValueBytes
Fixed integers1, 2, 4 or 8 bytes.
Bytes16, Bytes32, Bytes6416, 32 or 64 bytes as they are.
Byte arrayA 4-byte signed length, then the bytes.
ArrayA 4-byte signed count, then the items.
SmallStringA 1-byte length, then the UTF-8 bytes.
Zero-terminated stringThe UTF-8 bytes, then a zero byte. A string that contains a zero byte cannot be written.
Big integer (Int256)One header byte, the number of value bytes in its low six bits and 0x80 for a negative number, then the little-endian two’s complement bytes without the trailing 0x00 (or 0xFF) bytes. Zero is the single byte 0x00.
IntXA value that fits int64 is the header 0x08 (0x88 when negative) and 8 bytes. A larger value is a big integer.

A TxMsg is written in this order:

FieldBytes
Type1
Expiry8, signed, milliseconds
MaxGas8
MaxData8
GasFrom32
PayloadSmallString
MsgThe body of the type

A signed transaction, SignedTxMsg, is the TxMsg followed by its witnesses:

Message typeWitnesses after the message
TransferFungible, TransferNonFungibleSingle, TransferNonFungibleMulti, MintFungible, BurnFungible, MintNonFungible, BurnNonFungibleOne 64-byte signature by GasFrom.
The five ...GasPayer typesTwo 64-byte signatures: the gas payer’s, then the token owner’s (From of the body).
Call, CallMulti, Trade, PhantasmaA 4-byte count, then per witness a 32-byte address and a 64-byte signature. The gas payer must be one of them.
PhantasmaRawNone.

Every witness signs the serialized TxMsg. RequiredWitnesses(msg) returns the fixed witness set of a type, and EnvelopeBytes(msg, witnessCount) the size of the signed transaction before it is signed.

Enums And Flags

TypeValues or role
TxTypeTxTypeCall, TxTypeCallMulti, TxTypeTrade, the transfer, mint and burn types with their gas-payer forms, TxTypePhantasma, TxTypePhantasmaRaw.
ModuleIDModuleIDGovernance (0), ModuleIDToken (1), ModuleIDPhantasma (2), ModuleIDOrg (3), ModuleIDMarket (4), ModuleIDInternal.
TokenContractMethodToken module method ids; see Token Module Methods.
MarketContractMethod, ListingTypeMarket module method ids and the fixed-price listing type.
GovernanceContractMethodGovernanceMethodRegisterName, GovernanceMethodSetGasConfig.
TokenFlagsTokenFlagsNone, TokenFlagsBigFungible, TokenFlagsNonFungible.
TokensConfigFlagsRequireMetadata, RequireSymbol, RequireNFTMetaID, RequireNFTStandard, AllowExplicitNFTMetaIDMint.
MarketConfigFlagsPriceRequired, EnforceRoyalties, CanCancelEarly, CanPurchaseLate.
VMTypeCarbon dynamic metadata types, including scalar, fixed bytes, struct, dynamic, and array variants.
VMStructFlagsDynamic extras and sorted-struct flags.
StandardMeta... constantsReserved metadata keys: _i (StandardMetaID), the chain keys _a, _n, _x, _t, and the token keys for staking, inflation, pre-burn and VM script and ABI.

Schema And Metadata APIs

APIPurpose
PrepareStandardTokenSchemas(sharedMetadata)Builds the standard NFT schema layout.
BuildTokenSchemasFromFields(seriesMetadata, rom, ram)Builds schema objects from FieldType declarations.
ParseTokenSchemasJSON(data) / TokenSchemasFromJSON(data)Parses public schema JSON and converts it to SDK schema values.
VMTypeFromString(name), VMTypeName(type)Between type names such as Int32 and VMType.
SerializeTokenSchemas / SerializeTokenSchemasHex / BuildAndSerializeTokenSchemasSerializes token schemas for TokenInfo; the last one serializes the per-NFT standard set for nil.
VerifyTokenSchemasChecks standard NFT field requirements.
BuildTokenMetadata(fields)Serializes token-level metadata.
BuildTokenSeriesMetadata(schema, phantasmaSeriesID, metadata)Serializes series metadata.
BuildNFTRom(schema, phantasmaNFTID, metadata)Serializes the full NFT ROM with _i, for a direct mint.
BuildPhantasmaNFTRom(nftRomSchema, metadata)Serializes the ROM of a MintPhantasmaNonFungible mint, without _i and rom.
BuildPhantasmaNFTPublicMintSchema(nftRomSchema)The ROM schema without _i and rom, which that ROM follows.
BuildTokenInfo, CheckTokenSymbol, BuildSeriesInfoBuilds token and series structures used by lifecycle transactions.
MetadataField, FieldType, VMStructSchema, VMNamedVariableSchema, VMDynamicStruct, VMNamedDynamicVariable, VMDynamicVariable, VMStructArrayThe value and schema structures. VMDynamicStruct.WriteWithSchema and ReadWithSchema write and read a struct by a schema.

Standard metadata fields are name, description, imageURL, infoURL, and royalties. Token-level metadata also requires name, icon, url, and description. See Schemas And Metadata.

Transaction Structures And Signing

Structure or helperPurpose
TxMsgUnsigned Carbon transaction envelope.
SignedTxMsgSigned transaction plus witnesses.
WitnessAddress/signature witness entry.
TxMsgCall, TxMsgCallMultiModule call payloads. TxMsgCall.Sections, a MsgCallArgSections of CallArgSection values, builds the arguments of a call in a CallMulti from bytes and earlier results.
TxMsgTransferFungible, TxMsgTransferNonFungible*Fungible and NFT transfer payloads.
TxMsgMintFungible, TxMsgMintNonFungibleMint payloads.
TxMsgBurnFungible, TxMsgBurnNonFungible*Burn payloads.
TxMsgTrade, TxMsgPhantasma, TxMsgPhantasmaRawTrade and Phantasma VM payloads.
SignTxMsg, SignAndSerializeTxMsg, SignAndSerializeTxMsgHexSigning with key pairs, and serialization.
SignTxMsgWith, SignAndSerializeTxMsgWith, TxSigner, KeyPairSigner, KeyPairSignersSigning through any signer.
PlanAndSignWithKeys(msg, keys, config, options)Plans an unplanned message against a gas config and signs it; the function behind every ...AndSign builder.

Module argument structures:

StructureFields
MintFungibleArgsTokenID, To, Amount.
TransferFungibleArgsTo, From, TokenID, Amount.
TransferNonFungibleArgsTo, From, TokenID, InstanceIDs.
BurnFungibleArgsTokenID, From, Amount.
BurnNonFungibleArgsTokenID, From, InstanceIDs.
CreateTokenSeriesArgsTokenID, Info.
CreateMintedTokenSeriesArgsTokenID, Info, Address, ROMs, RAMs.
MintNonFungibleArgsTokenID, Address, Tokens (NFTMintInfo: SeriesID, ROM, RAM).
MintPhantasmaNonFungibleArgsTokenID, Address, Tokens (PhantasmaNFTMintInfo: PhantasmaSeriesID, ROM, RAM).
PhantasmaNFTMintResultPhantasmaNFTID, CarbonInstanceID: one entry of a MintPhantasmaNonFungible result.
UpdateTokenMetadataArgsTokenID, Metadata.
UpdateSeriesMetadataArgsTokenID, SeriesID, Metadata.
RegisterNameArgsAddress, Name.
TokenListing, MarketConfig, Market*ArgsMarket listing configuration and sell/cancel/buy/query argument payloads.
ChainConfig, GasConfig, TokensConfigThe chain, gas and token configuration. GasConfig.HasGasModelV2() tells the gas model.

Fee Planning

Builders carry no prices. A message is priced after it is built, from the message itself and the chain’s own gas configuration.

APIPurpose
PhantasmaRPC.Fees()The *rpc.FeePlanner of this chain. It caches the gas config and prices messages.
carbon.PlanFees(msg, config, options)The same calculation against a carbon.GasConfig the caller holds.
carbon.FeePlanMaxGas, MaxData, ExpectedGasBill, Kinds, Exact, EnvelopeBytes, Apply(msg).
carbon.FeePlanOptionsThe chain-state facts a caller may state, plus WitnessCount.
carbon.SummarizeFeePlan(plan)GasBill, GasOffer and StorageCeiling as decimal strings.
carbon.NativeFeeKindThe operation kinds the planner prices.
carbon.BurnedInstances(msg)The NFT instances a message burns, in any shape.
carbon.TxLimitsMaxGas, MaxData and Expiry, plus DefaultTxExpiry, DefaultExpiry() and ExpiryWithin.
carbon.TxSigner, carbon.KeyPairSignersAny witness that can sign, and the in-memory adapter.
carbon.PlanAndSignOptionsFeePlanOptions and TxLimits, taken by the Build...TxAndSign helpers.

Builders

BuilderPurpose
BuildTransferFungibleTx, BuildTransferNonFungibleTx, BuildMintFungibleTx, BuildBurnFungibleTx, BuildBurnNonFungibleTxNative transfers, mints and burns from a parameter struct; see Carbon.
BuildCreateTokenTxBuilds unsigned create-token TxMsg.
BuildCreateTokenTxAndSign / BuildCreateTokenTxAndSignHexSigned create-token bytes or hex.
BuildCreateTokenSeriesTxBuilds unsigned create-series TxMsg.
BuildCreateTokenSeriesTxAndSign / BuildCreateTokenSeriesTxAndSignHexSigned create-series bytes or hex.
BuildMintPhantasmaNonFungibleTx and its AndSign, AndSignHex formsA Phantasma NFT mint of one or more instances.
BuildMintPhantasmaNonFungibleSingleTx and its AndSign, AndSignHex formsThe same for one instance.
NowUnixMillis()The current time in milliseconds, the unit of TxMsg.Expiry.

Builders that accept user metadata return errors. MustBuild... variants are for constants and tests.

NFT Addresses

APIPurpose
GetNFTAddress(tokenID, instanceID)The address of one NFT instance.
UnpackNFTAddress(address)The token id and the instance id of an NFT address.
IsNFTAddress(address)Whether 32 bytes have the form of an NFT address.
UnpackNFTInstanceID(instanceID)The Carbon series id (low 32 bits) and the mint number (high 32 bits).

Result Parsers

ParserReturns
ParseCreateTokenResult(resultHex)Carbon token id.
ParseCreateTokenSeriesResult(resultHex)Carbon series id.
ParseMintNonFungibleResult(carbonTokenID, resultHex)Carbon NFT addresses derived from instance ids, for a direct mint.
ParseMintPhantasmaNonFungibleResult(resultHex)[]PhantasmaNFTMintResult with Phantasma NFT id and Carbon instance id.

Parsers do not verify transaction state. Fetch the transaction, require success, then parse TransactionResult.Result with the parser matching the operation.