As with ERC-20s, creating a token in Glittr is creating a contract.
After declaring a contract creation, we declare the creation of an asset. Tokens which are meant to be purely fungible can be created using the Simple Asset primitive.
After declaring the asset and its properties, we can add additional statements about minting, mining, allocation, and other mechanisms of obtention.
You can use GlittrSDK to deploy a new free mint contract with a prebuilt transaction
Copy import { Account , GlittrSDK , GlittrTransaction } from "@glittr-sdk/sdk"
async function deployFreeMintContract () {
const NETWORK = 'regtest'
const client = new GlittrSDK ({
network : NETWORK ,
apiKey : '1c4938fb-1a10-48c2-82eb-bd34eeb05b20' ,
glittrApi : "https://devnet-core-api.glittr.fi" , // devnet
electrumApi : "https://devnet-electrum.glittr.fi" // devnet
})
const account = new Account ({
network : NETWORK ,
wif : "cW84FgWG9U1MpKvdzZMv4JZKLSU7iFAzMmXjkGvGUvh5WvhrEASj" ,
})
const transaction = new GlittrTransaction ({
client ,
account
})
const txid = await transaction . contractDeployment .freeMint (
"GLITTR" , // ticker
18 , // divisibility
"1" , // amount per mint
"1000000" // supply cap
)
console .log ( "TXID : " , txid)
}
deployFreeMintContract ()
Alternatively, you can use our helper functions to manually construct the transaction, including its inputs and outputs :
Copy import { Account , addFeeToTx , BitcoinUTXO , electrumFetchNonGlittrUtxos , GlittrSDK , OpReturnMessage , Output , txBuilder } from "@glittr-sdk/sdk" ;
async function deployFreeMintContract () {
const NETWORK = 'regtest'
const client = new GlittrSDK ({
network : NETWORK ,
apiKey : < your api key here > ,
glittrApi : "https://devnet-core-api.glittr.fi" , // devnet
electrumApi : "https://devnet-electrum.glittr.fi" // devnet
})
const account = new Account ({
network : NETWORK ,
wif : "cW84FgWG9U1MpKvdzZMv4JZKLSU7iFAzMmXjkGvGUvh5WvhrEASj" ,
})
// Build the tx message
const tx : OpReturnMessage = {
contract_creation : {
contract_type : {
moa : {
divisibility : 18 ,
live_time : 0 ,
supply_cap : "1000000000" ,
ticker : "FKBTC" ,
mint_mechanism : { free_mint : { amount_per_mint : "10" , supply_cap : "1000000000" } }
}
} ,
} ,
};
// Helper function to fetch non glittr utxos
const utxos = await electrumFetchNonGlittrUtxos ( client .electrumApi , client .apiKey , account .p2wpkh ().address)
const nonFeeInputs : BitcoinUTXO [] = []
// Put tx message on output #0
const nonFeeOutputs : Output [] = [
{ script : txBuilder .compile (tx) , value : 0 }
]
// Helper function to add UTXO fee into the tx
const { inputs , outputs } = await addFeeToTx (
NETWORK ,
account .p2wpkh ().address ,
utxos ,
nonFeeInputs ,
nonFeeOutputs
)
const txid = await client .createAndBroadcastRawTx ({
account : account .p2wpkh () ,
inputs ,
outputs
})
console .log ( "TXID:" , txid);
}
deployFreeMintContract ()