Skip to content
Carbon Operations

C++ SDK Carbon Operations

The builders on Carbon cover transfers, mints, burns, token and series creation, and NFT mints. Every other module method is called with a Call message: a module id, a method id and the serialized arguments.

Builders Or A Call

NeedUse
A transfer, mint or burnNativeTxHelper; see Carbon.
A token, a series, an NFT mintThe token module builders; see Carbon.
Any other module methodA Blockchain::TxMsgCall with arguments written by hand.
Several calls in one transactionA Blockchain::TxMsgCall_Multi.
Tokens moving between several accounts at onceA Blockchain::TxMsgTrade.

A Module Call

The arguments are written with the Write... functions of Carbon/Carbon.h in the order the method reads them. This call deletes a series that holds no NFT:

using namespace phantasma::carbon;

// Token.DeleteTokenSeries reads the token id, then the Carbon series id.
ByteArray args;
WriteView w(args);
Write8u(carbonTokenId, w);
Write4u(carbonSeriesId, w);

Blockchain::TxMsg msg{};
msg.type = Blockchain::TxTypes::Call;
msg.expiry = DefaultExpiry();
msg.gasFrom = owner;
msg.call = Blockchain::TxMsgCall{ (uint32_t)ModuleId::Token, (uint32_t)TokenContract_Methods::DeleteTokenSeries, ByteView{ args.data(), args.size() }, {} };

// The message points into args, which has to outlive it.
String hash;
std::string error;
if( !SendTransaction(api, msg, { &keys }, config, SendOptions{}, hash, error) )
    return;

A Call takes its witnesses from the keys it is signed with, in that order, and the gas payer must be one of them. Each witness adds 96 bytes the chain bills; SendTransaction plans the call for the number of keys it is given.

Token Module Methods

ModuleId::Token (1). The method ids are the TokenContract_Methods values.

MethodArguments, in orderSigned by
TransferFungibleto (Bytes32), from (Bytes32), token id (uint64_t), amount (intx)from.
TransferNonFungibleto, from, token id, a count (int32_t) and that many instance ids (uint64_t)from.
CreateTokenTokenInfoThe owner; see Token Deployment.
MintFungibletoken id, to, amount (intx)The token owner.
BurnFungibletoken id, from, amount (intx)from.
CreateTokenSeriestoken id, SeriesInfoThe token owner.
MintPhantasmaNonFungibletoken id, to, a count and that many PhantasmaNftMintInfoThe series owner; see NFT Minting.
BurnNonFungibletoken id, from, a count and that many instance idsfrom, who owns the instances.
UpdateTokenMetadatatoken id, a VmDynamicStruct of fieldsThe token owner. The fields replace the fields of the same name or are added; the chain checks the result.
UpdateSeriesMetadatatoken id, Carbon series id (uint32_t), metadata as a byte arrayThe series owner. The bytes replace the series metadata; build them with TokenSeriesMetadataBuilder.
DeleteTokenSeriestoken id, Carbon series idThe token owner or the series owner, once no NFT of the series exists.
ApplyInflationtoken idAnyone. It mints the token’s scheduled inflation when a period is due.
MintNonFungible, CreateMintedTokenSeriesRefused: both take an NFT id chosen by the caller, which the token configuration disables.
SetTokensConfigTokensConfigGovernance only.

The Get... method ids read state; the RPC methods on RPC return the same data without a transaction.

Market Module Methods

Module id 4; ModuleId has no name for it. A listing sells one NFT for a fungible token at a fixed price.

Method idMethodArguments, in orderRules
0SellTokenfrom (Bytes32), token id, instance id, quote token id (uint64_t), price (intx), end date (int64_t, milliseconds)Signed by the NFT owner. The NFT moves to the market until it is bought or the listing is cancelled. The quote token must be fungible, the end date in the future, the price not negative and, with the PriceRequired rule, above zero.
4BuyTokenfrom, token id, instance idSigned by the buyer, who pays the price in the quote token. Without the CanPurchaseLate rule, only before the end date.
2CancelSaletoken id, instance idWithout the CanCancelEarly rule, only after the end date. Signed by the seller, or by anyone once the delisting grace after the end date has passed. The NFT returns to the seller.

Methods 1, 3 and 5 are the same three by token symbol and Phantasma NFT id; 6, 7 and 8 read listings.

With the EnforceRoyalties rule, a sale pays up to three royalties out of the price, at 10,000,000 per 1%:

  1. The royalties value of the token metadata, to the token owner.
  2. The royalties value of the series metadata, to the series owner.
  3. The royalties value of the NFT’s ROM, to the account the NFT was minted to.

Each is a share of what remains of the price after the ones before it. The seller receives the rest. The chain’s defaults turn on PriceRequired and EnforceRoyalties and set a delisting grace of one day. TokenListing in Carbon/Contracts/Market.h is the listing a read returns.

Governance Module Methods

ModuleId::Governance (0). GovernanceContract_Methods::RegisterName takes the address (Bytes32) and the name (SmallString) and is signed by that address. One name per address, at most maxNameLength characters, lowercase ASCII letters, digits and _. The fee is policyFeeRegisterName halved for every character after the first, so short names cost more. A registered name cannot be removed. The other governance methods are for governance only.

Several Calls In One Transaction

A TxMsgCall_Multi holds numCalls calls and runs them in order, in one transaction: they all complete or none does. A call can take part of its arguments from the result of an earlier call. Its sections then hold numArgSections_negative, the negated number of sections. Each section holds either bytes or a negative registerOffset, where -1 means the result of the call before. The sections are joined into the arguments.

Trades

A TxMsgTrade moves tokens of several accounts in one transaction: fungible mints, NFT mints, fungible transfers, NFT transfers, fungible burns and NFT burns, run in that order. Each entry names its own from, and every such account signs. Two accounts can swap tokens this way without trusting each other. NFT mints in a trade take an NFT id chosen by the caller and are refused.

Read A Message Back

using namespace phantasma::carbon;

Allocator storage;
Blockchain::SignedTxMsg signedMsg;
ByteView signedPortion;
const ByteView bytes{ signedTx.data(), signedTx.size() };
if( !Blockchain::ParseSignedTx(signedMsg, signedPortion, bytes, storage) )
    return; // cut short, an unknown type, or a field that does not fit

uint64_t offer = signedMsg.msg.maxGas;

ParseTx(msg, bytes, storage) reads an unsigned message. Both read the bytes the way the chain reads them and refuse a message that is cut short. The Allocator and the bytes must outlive the parsed message, which points into them.

Related Pages