Crown Platform NFT Framework

Artem
Artem
Jun 20 · 9 min read

Non-fungible Tokens on the Crown Core

Crown NFT vs Ethereum ERC-721 NFT

NFT Data Structure

Design Your Blockchain Solution

/// @title ERC-721 Non-Fungible Token Standard
interface ERC721 /* is ERC165 */
{
Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
function balanceOf(address _owner) external view returns (uint256); function ownerOf(uint256 _tokenId) external view returns (address); function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
function approve(address _approved, uint256 _tokenId) external payable;
function setApprovalForAll(address _operator, bool _approved) external;
function getApproved(uint256 _tokenId) external view returns (address);
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
    /// NF token protocol unique symbol/identifier, can be an a    abbreviated name describing this NF token type
/// Represented as a base32 string, can only contain characters: .abcdefghijklmnopqrstuvwxyz12345
/// Minimum length 3 symbols, maximum length 12 symbols
uint64_t tokenProtocolId;
/// Full name for this NF token type/protocol
/// Minimum length 3 symbols, maximum length 24
std::string tokenProtocolName;
/// URI to schema (json/xml/binary) describing metadata format
std::string tokenMetadataSchemaUri;
/// MIME type describing metadata content type
std::string tokenMetadataMimeType;
/// Defines if metadata is embedded or contains a URI
/// It's recommended to use embedded metadata only if it's shorter than URI
bool isMetadataEmbedded;
/// Owner of the NF token protocol
CKeyID tokenProtocolOwnerId;

NF Token Registration and API interface

nftoken register/issue "nfTokenProtocol" "tokenId" "tokenOwnerAddr" "tokenMetadataAdminAddr" "metadata"Creates and sends a new non-fungible token transaction.
Arguments:
1. "nfTokenProtocol" (string, required) A non-fungible token protocol symbol to use in the token creation. The protocol name must be valid and registered previously.
2. "nfTokenId" (string, required) The token id in hex. The token id must be unique in the token type space."3."nfTokenOwnerAddr" (string, required) The token owner key, can be used in any operations with the token. The private key belonging to this address may be or may be not known in your wallet.4. "nfTokenMetadataAdminAddr" (string, optional, default = \"0\"). The metadata token administration key, can be used to modify token metadata. The private key does not have to be known by your wallet. Can be set to 0.5. "nfTokenMetadata" (string, optional) metadata describing the token. It may contain text or binary in hex/base64.
{
“name”: “Percival”,
“description”: “A knight of the Round Table”,
“image”: “https://percival-image.link
}
nftoken get ckt 2772eeb3a5486f773ad7e47413424356da55db94c7f8e0528fcba5079ddeb8ed
{
“blockHash” : “000001b031c4832eb185b05475bb37a6d320b6a531a48cc1cdf9300760e84388”,
“registrationTxHash” : “ce1444b48cdd83761afa79f3089d2d433a417ea3a6eb2cfc403dc0bf4e7f48c6”,
“height” : 5197,
“timestamp” : 1561019190,
“nftProtocolId” : “ckt”,
“nftId” : “2772eeb3a5486f773ad7e47413424356da55db94c7f8e0528fcba5079ddeb8ed”,
“nftOwnerKeyId” : “CRWJKC453SVnczLQD6opqJVMuHDqNWwaJAgV”,
“metadataAdminKeyId” : “CRWD4W7PauajWooq8vmtzaxNzEEED5yL3FdZ”,
“metadata” : “https://ipfs.io/ipfs/QmPiYzMQbSPxsKC2b6CHEUHWfqFHjX9bHSu6YVpiopzvTx
}
nftoken getbytxid ce1444b48cdd83761afa79f3089d2d433a417ea3a6eb2cfc403dc0bf4e7f48c6
nftoken list ckt
nftoken list * CRWJKC453SVnczLQD6opqJVMuHDqNWwaJAgV
nftoken totalsupply ckt
nftoken balanceof CRWJKC453SVnczLQD6opqJVMuHDqNWwaJAgV
nftoken ownerof ckt 2772eeb3a5486f773ad7e47413424356da55db94c7f8e0528fcba5079ddeb8ed

Code Example

int main()
{
CURL * curl = curl_easy_init();
curl_slist * headers = nullptr;
Nft newNft;
if (curl != nullptr)
{
std::string getNewAddr(R"({"jsonrpc": "1.0", "id": "nftest", "method": "getnewaddress", "params": [] })");
headers = curl_slist_append(headers, R"("content-type: text/plain;")"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:43001/");
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, getNewAddr.size());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, getNewAddr.c_str());
curl_easy_setopt(curl, CURLOPT_USERPWD, "crownrpc:bogus");
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
// Gen owner address
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, GetNewAddressFunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &newNft.OwnerAddress);
curl_easy_perform(curl);
// Gen admin address
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &newNft.AdminAddress);
curl_easy_perform(curl);
// Register new NFT
rapidjson::Document nfTokenRegDoc;
nfTokenRegDoc.SetObject();
nfTokenRegDoc.AddMember("jsonrpc", "1.0", nfTokenRegDoc.GetAllocator());
nfTokenRegDoc.AddMember("id", "nftest", nfTokenRegDoc.GetAllocator());
nfTokenRegDoc.AddMember("method", "nftoken", nfTokenRegDoc.GetAllocator());
rapidjson::Value params(rapidjson::kArrayType);
params.PushBack(rapidjson::Value("register").Move(), nfTokenRegDoc.GetAllocator());
params.PushBack(rapidjson::Value("doc").Move(), nfTokenRegDoc.GetAllocator());
params.PushBack(rapidjson::Value(rapidjson::StringRef(newNft.TokenId.c_str())).Move(), nfTokenRegDoc.GetAllocator());
params.PushBack(rapidjson::Value(rapidjson::StringRef(newNft.OwnerAddress.c_str())).Move(), nfTokenRegDoc.GetAllocator());
params.PushBack(rapidjson::Value(rapidjson::StringRef(newNft.AdminAddress.c_str())).Move(), nfTokenRegDoc.GetAllocator());
params.PushBack(rapidjson::Value(rapidjson::StringRef(newNft.Metadata.c_str())).Move(), nfTokenRegDoc.GetAllocator());
nfTokenRegDoc.AddMember("params", params, nfTokenRegDoc.GetAllocator()); rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
nfTokenRegDoc.Accept(writer);
std::string nftRegJsonStr = buffer.GetString();
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, nftRegJsonStr.size());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, nftRegJsonStr.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NfTokenRegFunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &newNft);
curl_easy_perform(curl);
}
return 0;
}

Crown Platform

Crown is a digital token and blockchain platform enabling independence serving individuals & businesses. We are focused on legal compliance and transparency utilizing our decentralized governance model.

Thanks to J. Herranz.

Artem

Written by

Artem

Crown Platform

Crown is a digital token and blockchain platform enabling independence serving individuals & businesses. We are focused on legal compliance and transparency utilizing our decentralized governance model.