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.
Compiling
Section titled “Compiling”API Enpoint:
Section titled “API Enpoint:”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 = await 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 Enpoint:
Section titled “API Enpoint:”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 types of features currently supported, each with a different FeatureName enum:
0: Evolving1: Royalty2: Multi AssetRoyalty
Section titled “Royalty”Percent
Section titled “Percent”{ ... "Features": [ { "FeatureName": 1, "FeatureFeatures":{ "RoyaltyAmount": 0.05, // 5% "RoyaltyPayToAddress": "Rabc123...", "RoyaltyType": 1 } }, ]}{ ... "Features": [ { "FeatureName": 1, "FeatureFeatures":{ "RoyaltyAmount": 5, // 5 VFX "RoyaltyPayToAddress": "Rabc123...", "RoyaltyType": 0 } }, ]}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”{ ... "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": 1679505579, "EvolveBlockHeight": null }, ] } ]}Retrieving Data
Section titled “Retrieving Data”Once the smart contract is compile and minted, it will be available to read back through the API
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}/{QUERY}Code Example
Section titled “Code Example”const searchNfts = async (query, page = 1) => { const url = `${CLI_BASE_URL}/scapi/scv1/GetAllSmartContracts/${page}/${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}/{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.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 len(data) < 1: return None
return data[0]