Friends, hello everyone!
According to the accepted proposal, we publish the Technical Documentation for the TNFT Space Stations.
The TrueNFT smart contract system consists of many contracts, libraries, interfaces and resolvers.
GitHub - tonlabs/True-NFT
Contracts:
Index.sol # A contract to find NFT on the blockchain.
IndexBasis.sol # Collection(root) contract to search in BC
Data.sol # NFT contract
DataChunk.sol # contract - media repository
NftRoot.sol # collection contract
NftRootBase.sol # collection contract with an example of basic implementation
NftRootCustomMint.sol # contract collections with their own logic
Checks.sol # verifiable contract
Description of custom Data contract methods
Structure of NFT:
struct SpaceStation{
string station_name;
uint8 remoteness;
uint16 level;
string race;
uint32 crd_x;
uint32 crd_y;
uint8 res_license;
uint8 trade_license;
uint8 prod_license;
uint16 res_lvl;
uint16 trade_lvl;
uint16 prod_lvl;
}
The NFT initialization method takes arguments to set the data to the structure of the CS itself
function stationInit(
string station_name,
uint8 remoteness,
uint16 level,
string race,
uint32 crd_x,
uint32 crd_y,
uint8 res_license,
uint8 trade_license,
uint8 prod_license,
uint16 res_lvl,
uint16 trade_lvl,
uint16 prod_lvl,
uint128 royalty,
uint128 royaltyMin
) public
Method function setStationLevel(uint16 _res_lvl,uint16 _trade_lvl,uint16 _prod_lvl)public
allows you to set the level for the Station.
Method function setLicense(uint8 _res_lic,uint8 _trade_lic,uint8 _prod_lic)public
allows you to set the license level.
Method function setCoordinates(uint32 _crdX,uint32 _crdY,uint8 _remoteness)public
allows you to set the coordinates for the Station
Method function setStationName(string _station_name)public
allows you to set a name for the Station.
Method function getStation()
возвращает структуру КС
Method
function setMetadata(
optional(uint128) height,
optional(uint128) width,
optional(uint128) duration,
optional(string) extra,
optional(string) json
) public
allows you to change the NFT metadata.
You can change an individual argument without necessarily using all of them.
Description of the custom methods of the manageTnft.sol contract
The contract is for managing the entire collection and for depositing the collection.
When you apply a contract to the constructor you need to pass
constructor(
TvmCell codeRoot, # Collection contract code
TvmCell codeIndex, # Index Contract Code
TvmCell codeIndexBasis, # IndexBasis Contract Code
TvmCell codeData, # Data Contract Code
TvmCell codeDataChunk # DataChunk Contract Code
) public
Command for manageTnft deploying manageTnft:
./tonos-cli deploy --abi manageTnft.abi.json --sign manageTnft.keys.json manageTnft.tvc
{"codeRoot":"",
"codeIndex":"",
"codeIndexBasis":"",
"codeData":"",
"codeDataChunk":""}
They are saved in the corresponding variables in the contract and used for Root contract deployment
Contract variables:
address _addrRoot; # The address of the root contract, which is set during the deployment Root
uint128 currentID = 0; # ID current NFT
uint128 _baseRoyalty; # Royalty payable on sale 1000 = 1%
uint128 _baseRoyaltyMin; # The royalty is the minimum payable even for a simple transfer.
uint16 version = 0; # The version of the contract used in the method onCodeUpgrade
Method function getCode(uint8 _id) public view returns(TvmCell)
returns the code of the contract stored in the variables
_id =
_codeRoot; //0
_indexCode; //1
_indexBasisCode;//2
_dataCode; //3
_dataChunkCode; //4
Method call command:
./tonos-cli run '0:адрес_контракта_manageTnft' getCode '{"_id":0}' --abi manageTnft.abi.json
Methods:
function updateIndexCode(TvmCell newIndexCode)
function updateIndexBasisCode(TvmCell newIndexBasisCode)
function updateDataCode(TvmCell newDataCode)
function updateDataChunkCode(TvmCell newDataChunkCode)
take the code of the corresponding contract as an argument and make a crosscontract call to change the code of the corresponding contract in the Root contract.
Commands:
./tonos-cli run '0:адрес_контракта_manageTnft' updateIndexCode'{"newIndexCode":"string"}' --abi manageTnft.abi.json --sign manageTnft.keys.json
--
./tonos-cli run '0:адрес_контракта_manageTnft' updateIndexBasisCode'{"newIndexBasisCode":"string"}' --abi manageTnft.abi.json --sign manageTnft.keys.json
--
./tonos-cli run '0:адрес_контракта_manageTnft' updateDataCode'{"newDataCode":"string"}' --abi manageTnft.abi.json --sign manageTnft.keys.json
--
./tonos-cli run '0:адрес_контракта_manageTnft' updateDataChunkCode'{"newDataChunkCode":"string"}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Method:
function updateRootCode(TvmCell newRootCode)
updates the Root contract code in the manageTnft contract
Updates call command:
./tonos-cli run '0:адрес_контракта_manageTnft' updateRootCode '{"newRootCode":"string"}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Method:
function mintNft(
string name, # Name of NFT
string description, # Description of NFT
uint256 contentHash, # Hash of content
string mimeType, # media type in mimeType
uint8 chunks, # How many parts a media file is divided into NFT
uint128 chunkSize, # The size of each part in bytes
uint128 size, # Total media file size in bytes
Meta meta, # Metadata
address owner # Address of owner
)public onlyOwner returns(address dataAddr)
takes the necessary arguments for deplotting the Data contract and returns the address of the deplotized Data contract
Methods:
function setRoyalty(uint128 royalty, uint128 royaltyMin)
sets the royalty for the collection
Method:
function changeRoyaltyToNft(address nftData,uint128 royalty, uint128 royaltyMin)
changes the royalty of a particular NFT by taking the address of the NFT and the royalty as arguments
Command:
./tonos-cli call '0:адрес_контракта_manageTnft' setRoyalty '{"royalty":5000,"royaltyMin":300000000}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Methods:
function setStationLevel(address nftData,uint16 res_lvl,uint16 trade_lvl,uint16 prod_lvl)
function setLicense(address nftData,uint8 res_lic,uint8 trade_lic,uint8 prod_lic)
function setCoordinates(address nftData,uint32 crdX,uint32 crdY,uint8 remoteness)
function setStationName(address nftData,string station_name)
change the corresponding parameters of the NFT itself after initialization.
Commands:
./tonos-cli call '0:адрес_контракта_manageTnft' setStationLevel '{"_nftData":"0:e2dedbed8a6cb929fc032112aa97e3a16e60d1ffcad15225e3a47ab198dd6fae","_res_lvl":5,"_trade_lvl":5,"_prod_lvl":5}' --abi manageTnft.abi.json --sign manageTnft.keys.json
--
./tonos-cli call '0:адрес_контракта_manageTnft' setLicense '{"_nftData":"0:e2dedbed8a6cb929fc032112aa97e3a16e60d1ffcad15225e3a47ab198dd6fae","_res_lic":3,"_trade_lic":3,"_prod_lic":3}' --abi manageTnft.abi.json --sign manageTnft.keys.json
--
./tonos-cli call '0:адрес_контракта_manageTnft' setCoordinates '{"_nftData":"0:e2dedbed8a6cb929fc032112aa97e3a16e60d1ffcad15225e3a47ab198dd6fae","_name":"NewTestName","_crdX":44444,"_crdY":55555,"_remoteness":3}' --abi manageTnft.abi.json --sign manageTnft.keys.json
--
./tonos-cli call '0:адрес_контракта_manageTnft' setStationName '{"_nftData":"0:e2dedbed8a6cb929fc032112aa97e3a16e60d1ffcad15225e3a47ab198dd6fae","_name":"NewTestName"}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Method initializing of NFT:
function stationInit(
address nftDataAddr,
string station_name,
uint8 remoteness,
uint16 level,
string race,
uint32 crd_x,
uint32 crd_y,
uint8 res_license,
uint8 trade_license,
uint8 prod_license,
uint16 res_lvl,
uint16 trade_lvl,
uint16 prod_lvl
)
Command:
./tonos-cli call '0:адрес_контракта_manageTnft' stationInit '{"nftDataAddr":"0:957b77baa220573afbe18b25e84349ddfea38f477a1aa2f0595773a34d072223","station_name":"TestName KS","remoteness":99,"level":100,"race":"Minter","crd_x":11111,"crd_y":22222,"res_license":1,"trade_license":2,"prod_license":3,"res_lvl":1,"trade_lvl":2,"prod_lvl":3}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Method:
function deployNftRoot(
MintType mintType,
uint128 fee,
string name,
string descriprion,
bytes icon
)
Deploys the root contract by passing the parameters of the contract description and the icon.
Fee and mintType are not necessary in our case
Command:
./tonos-cli call '0:адрес_контракта_manageTnft' deployNftRoot '{"mintType":0,"fee":5000,"name":"SS","descriprion":"short","icon":""}'--abi manageTnft.abi.json --sign manageTnft.keys.json
Method:
function getRootAddr()
Returns the address of the Root contract
Command
./tonos-cli run '0:адрес_контракта_manageTnft' getRootAddr '{}' --abi manageTnft.abi.json
Method:
function deployDataChunk(address _addrData,bytes chunk, uint128 chunkNumber)
Deploy parts of a media file
Command:
./tonos-cli call '0:адрес_контракта_manageTnft' deployDataChunk '{"_addrData":"0:e9b87723ac49dcdc88e0f52679716e29f619b48b47e3a59cfe2b0b4d58299c1b","chunkNumber":1,"chunk":""}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Method:
function putOnSaleNft(address nftDataAddr,uint128 price
)
puts up for sale NFT taking arguments: NFT address and price in nanotons
1_000_000_000 = 1 Ever
Command:
./tonos-cli call '0:адрес_контракта_manageTnft' putOnSaleNft '{"nftDataAddr":"e66c581822fe642fb3219979289f6cb2d30368b1bdac0dd4e26568dd829e86ef","price":1500000000}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Method:
function transferNft(address nftDataAddr,address addrTo)
transfer the NFT from the author’s address
Command:
./tonos-cli call '0:адрес_контракта_manageTnft' transferNft '{"nftDataAddr":"e66c581822fe642fb3219979289f6cb2d30368b1bdac0dd4e26568dd829e86ef","addrTo":"0:09a13e4faa1fa7d1a98002213571e7deddd0f0453450342dcbdbe2f6354f45ad"}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Method:
function calcDataAddr(uint256 id)
calculates the Data address of the contract by its NFT ID
Command:
./tonos-cli run '0:адрес_контракта_manageTnft' calcDataAddr'{"id":1}' --abi manageTnft.abi.json
Method:
function setMetadata(
address nftDataAddr,
optional(uint128) height,
optional(uint128) width,
optional(uint128) duration,
optional(string) extra,
optional(string) json
)
Change of meta:
./tonos-cli call '0:адрес_контракта_manageTnft' setMetadata '{"nftDataAddr":"e66c581822fe642fb3219979289f6cb2d30368b1bdac0dd4e26568dd829e86ef","extra":"test"}' --abi manageTnft.abi.json --sign manageTnft.keys.json
Sets the metadata of an individual NFT. Executes a cross call to the Data contract