Compiling & Minting
Overview
Section titled “Overview”Compiling and Minting a smart contract is fairly straightforward. The first step is to compile the smart contract based on a JSON payload which will return the information needed for the second step, minting the smart contract. Then you hit an endpoint to mint it which will broadcast the transaction.
Trillium has no gas and no execution metering, but the mint transaction still pays the normal size-based VFX network fee, which is burned. The Transaction object in the compile response shows the Fee the mint will pay.
Compiling
Section titled “Compiling”API Endpoint:
Section titled “API Endpoint:”POST http://localhost:7292/scapi/scv1/CreateSmartContractBasic Payload Example:
{ "Name": "Smart Contract Name", "MinterName": "Minter's Name", "Description": "Description Goes Here", "SmartContractAsset": { "AssetId": "00000000-0000-0000-0000-000000000000", "Name": "welness.jpg", "AssetAuthorName": "Author's Name", "Location": "/path/to/asset.jpg", "Extension": "jpg", "FileSize": 1024 }, "IsPublic": false, "SmartContractUID": "00000000-0000-0000-0000-000000000000", "Features": [], "MinterAddress": "Rabc123..."}Response Example:
[ { "Success": true, "SmartContract": { "Id": 63, "Name": "Test", "Description": "Hello world", "MinterAddress": "Rabc123...", "MinterName": "Minter's Name", "SmartContractAsset": { "AssetId": "00000000-0000-0000-0000-000000000000", "Name": "welness.jpg", "AssetAuthorName": "Author's Name", "Location": "/path/to/asset.jpg", "Extension": "jpg", "FileSize": 1024 }, "IsPublic": false, "SmartContractUID": "a4a245fba5a282da1bf02a72cf267aab:123456789", "IsMinter": true, "IsPublished": false, "Features": [] }, "SmartContractCode": "--SMART CONTRACT CODE (string)--", "Transaction": "-- TRANSACTION (dict) --" }]Code Example
Section titled “Code Example”const compileNft = async () => { const payload = { Name: "Smart Contract Name", MinterName: "Minter's Name", Description: "Description Goes Here", SmartContractAsset: { AssetId: "00000000-0000-0000-0000-000000000000", Name: "file.jpg", AssetAuthorName: "Author's Name", Location: "/path/to/file.jpg", Extension: "jpg", FileSize: 488734, }, IsPublic: false, SmartContractUID: "00000000-0000-0000-0000-000000000000", Features: [], MinterAddress: "xDnL4MCGtgHu85JJHdN1fkXinHzKaqVQ59", };
const url = `${CLI_BASE_URL}/scapi/scv1/CreateSmartContract`; const request = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), });
const data = await request.json();
if (data[0]["Success"] == true) { return data[0]["SmartContract"]["SmartContractUID"]; }
return null;};import requestsimport json
def compile_nft(): payload = { "Name": "Smart Contract Name", "MinterName": "Minter's Name", "Description": "Description Goes Here", "SmartContractAsset": { "AssetId": "00000000-0000-0000-0000-000000000000", "Name": "file.jpg", "AssetAuthorName": "Author's Name", "Location": "/path/to/file.jpg", "Extension": "jpg", "FileSize": 488734, }, "IsPublic": False, "SmartContractUID": "00000000-0000-0000-0000-000000000000", "Features": [], "MinterAddress": "xDnL4MCGtgHu85JJHdN1fkXinHzKaqVQ59" }
url = f"{CLI_BASE_URL}/scapi/scv1/CreateSmartContract" headers = {"Content-Type": "application/json"} response = requests.post(url, headers=headers, data=json.dumps(payload))
data = response.json()
if data[0]["Success"] == True: return data[0]["SmartContract"]["SmartContractUID"]
return NoneMinting
Section titled “Minting”API Endpoint:
Section titled “API Endpoint:”GET http://localhost:7292/scapi/scv1/MintSmartContract/{SMART_CONTRACT_UID}Response Example:
"Smart contract has been published to mempool"Code Example
Section titled “Code Example”const mintNft = async (smartContractUid) => { const url = `${CLI_BASE_URL}/scapi/scv1/MintSmartContract/${smartContractUid}`; const request = await fetch(url);
const data = await request.text(); if (data == "Smart contract has been published to mempool") { return true; }
return false;};def mint_nft(smart_contract_uid): url = f"{CLI_BASE_URL}/scapi/scv1/MintSmartContract/{smart_contract_uid}" response = requests.get(url) data = response.text
if data == "Smart contract has been published to mempool": return True
return FalseAdding Features
Section titled “Adding Features”You can add features to your smart contract by just including them in the Features: [] array.
There are three NFT feature types you can set through this payload, each with a different FeatureName enum value:
0: Evolving1: Royalty2: Multi AssetRoyalty
Section titled “Royalty”Percent
Section titled “Percent”{ ... "Features": [ { "FeatureName": 1, "FeatureFeatures":{ "RoyaltyAmount": 0.05, // 5% "RoyaltyPayToAddress": "Rabc123...", "RoyaltyType": 1 } }, ]}RoyaltyAmount is a fraction and must be below 1 (0.99 at most).
Multi Asset
Section titled “Multi Asset”{ ... "Features": [ { "FeatureName": 2, "FeatureFeatures": [ { "AssetId": "00000000-0000-0000-0000-000000000000", "AssetAuthorName": "Author's Name", "Location": "/path/to/asset1.jpg", "Extension": "jpg", "FileSize": 1024, "FileName": "asset1.jpg" }, { "AssetId": "00000000-0000-0000-0000-000000000000", "AssetAuthorName": "Author's Name", "Location": "/path/to/asset2.jpg", "Extension": "jpg", "FileSize": 1024, "FileName": "asset2.jpg" } ] } ]}Evolving
Section titled “Evolving”Minter Controlled Evolution
Section titled “Minter Controlled Evolution”{ ... "Features": [ { "FeatureName":0, "FeatureFeatures":[ { "Name": "Phase 1", "Description": "Description of phase 1", "IsDynamic": false, "EvolutionState": 1, "IsCurrentState": false, "SmartContractAsset": { "AssetId": "00000000-0000-0000-0000-000000000000", "AssetAuthorName": "Author's Name", "Location": "/path/to/asset1.jpg", "Extension": "jpg", "FileSize": 1024, "FileName": "asset1.jpg" }, "EvolveDate": null, "EvolveBlockHeight": null }, { "Name": "Phase 2", "Description": "Description of phase 2", "IsDynamic": true, "EvolutionState": 2, "IsCurrentState": false, "SmartContractAsset": { "AssetId": "00000000-0000-0000-0000-000000000000", "AssetAuthorName": "Author's Name", "Location": "/path/to/asset2.jpg", "Extension": "jpg", "FileSize": 1024, "FileName": "asset2.jpg" }, "EvolveDate": null, "EvolveBlockHeight": null } ] } ]}Block Height Evolution
Section titled “Block Height Evolution”{ ... "Features": [ { "FeatureName":0, "FeatureFeatures":[ { "Name": "Phase 1", "Description": "Description of phase 1", "IsDynamic": true, "EvolutionState": 1, "IsCurrentState": false, "SmartContractAsset": { "AssetId": "00000000-0000-0000-0000-000000000000", "AssetAuthorName": "Author's Name", "Location": "/path/to/asset1.jpg", "Extension": "jpg", "FileSize": 1024, "FileName": "asset1.jpg" }, "EvolveDate": null, "EvolveBlockHeight": 1000000 }, ] } ]}DateTime Evolution
Section titled “DateTime Evolution”EvolveDate is an ISO 8601 date-time string, not a Unix timestamp.
{ ... "Features": [ { "FeatureName":0, "FeatureFeatures":[ { "Name": "Phase 1", "Description": "Description of phase 1", "IsDynamic": true, "EvolutionState": 1, "IsCurrentState": false, "SmartContractAsset": { "AssetId": "00000000-0000-0000-0000-000000000000", "AssetAuthorName": "Author's Name", "Location": "/path/to/asset1.jpg", "Extension": "jpg", "FileSize": 1024, "FileName": "asset1.jpg" }, "EvolveDate": "2023-03-22T17:19:39Z", "EvolveBlockHeight": null }, ] } ]}Retrieving Data
Section titled “Retrieving Data”Once the smart contract is compiled and minted, it will be available to read back through the API. These endpoints return only contracts owned by accounts in this node’s wallet, nine per page.
Listing
Section titled “Listing”GET http://localhost:7292/scapi/scv1/GetAllSmartContracts/{PAGE}Code Example
Section titled “Code Example”const listNfts = async (page = 1) => { const url = `${CLI_BASE_URL}/scapi/scv1/GetAllSmartContracts/${page}`; const request = await fetch(url);
const data = await request.json();
if (!data) { return null; }
if (data["Count"] == 0) { console.log("No NFTs found"); return []; }
return data["Results"];};def list_nfts(page=1): url = f"{CLI_BASE_URL}/scapi/scv1/GetAllSmartContracts/{page}" response = requests.get(url) data = response.json()
if not data: return None
if data["Count"] == 0: print("No NFTs found") return []
return data["Results"]Searching
Section titled “Searching”GET http://localhost:7292/scapi/scv1/GetAllSmartContracts/{PAGE}/false/false/{QUERY}The two false segments are excludeToken and tokensOnly. From Core 9.0.2, GetAllSmartContracts/{PAGE}/{QUERY} also searches, unless the query is true or false. Earlier versions read that second segment as excludeToken and answered 400, so the four-segment form works on every version.
Code Example
Section titled “Code Example”const searchNfts = async (query, page = 1) => { const url = `${CLI_BASE_URL}/scapi/scv1/GetAllSmartContracts/${page}/false/false/${query}`; const request = await fetch(url);
const data = await request.json();
if (!data) { return null; }
if (data["Count"] == 0) { console.log("No NFTs found"); return []; }
return data["Results"];};def search_nfts(query, page=1): url = f"{CLI_BASE_URL}/scapi/scv1/GetAllSmartContracts/{page}/false/false/{query}" response = requests.get(url) data = response.json()
if not data: return None
if data["Count"] == 0: print("No NFTs found") return []
return data["Results"]Retrieve
Section titled “Retrieve”GET http://localhost:7292/scapi/scv1/GetSingleSmartContract/{SMART_CONTRACT_UID}Code Example
Section titled “Code Example”const retrieveNft = async (smartContractUid) => { const url = `${CLI_BASE_URL}/scapi/scv1/GetSingleSmartContract/${smartContractUid}`; const request = await fetch(url);
const data = await request.json(); if (!data || data.length < 1) return null; return data[0];};def retrieve_nft(smart_contract_uid): url = f"{CLI_BASE_URL}/scapi/scv1/GetSingleSmartContract/{smart_contract_uid}" response = requests.get(url) data = response.json()
if not data: return None
return data[0]