Tangocrypto
Search…
⌃K

Minting assets

Minting multiple assets in multiple wallets with one transaction
Use cases
  • Airdrops with NFTs and FTs.
  • Minting items on games.
  • Applications generating NFTs in real time like supply chain
In this example we are going to mint 3 assets, two of them go to the firs address and one to the second address.
Here is the code:
const { Tangocrypto, Network } = require('@tango-crypto/tangocrypto-js');
const tc = new Tangocrypto({
apiKey: 'XXXXXXXXXXXXXX',
appId: 'XXXXXXXXXXXXXXX',
network: Network.CARDANO_TESTNET
})
async function mint() {
const txClient = tc.transaction();
const addrClient = tc.address();
// get address utxos (take into account any pagination here)
const inputs = (await addrClient.listAddressUtxos('addr_test1qpemm54tmynjhuyw0qhzdpnras29c3pc8gxvc4afpsa3uwglmrag6mlare663x64ugkkv8nqhqg3z6u78xa49fq6wmts55h5y9')).result.data;
// build tx
const request = {
"inputs": inputs.map(i => ({
address: i.address,
index: i.index,
hash: i.hash,
value: i.value,
assets: i.assets.map(a => ({
policy_id: a.policy_id,
asset_name: a.asset_name,
quantity: a.quantity
}))
})), // use address inputs here as spending utxos
"recipients": {
"addr_test1qzy4e509u7jtztnn0p3v6rypup5w48t63pgkhtsup6anumqrejvpmpdfe7zt662gdx98f3d5a0phjrh6hvxyjhecpe3q422hpz": [{
"policy_id": "18ed282beda4bec13226c427d4744d2642ba2cef404470b62ae184d8",
"asset_name": "Tango#001",
"quantity": 1,
"metadata": {
"721": {
"cdf7a949cca0d57a27f862d525e4d4c734c1d503cbc7f04c1ac2350e": {
"Tango#001": {
"name": "Tango #001",
"image": "ipfs://QmbFhLR5C6BmTW7apgDMVmGozLuEUZwoezcgHQeULT59M5",
"description": "Flash mint"
}
}
}
}
},
{
"policy_id": "18ed282beda4bec13226c427d4744d2642ba2cef404470b62ae184d8",
"asset_name": "Tango#003",
"quantity": 1,
"metadata": {
"721": {
"cdf7a949cca0d57a27f862d525e4d4c734c1d503cbc7f04c1ac2350e": {
"Tango#003": {
"name": "Tango #003",
"image": "ipfs://QmbFhLR5C6BmTW7apgDMVmGozLuEUZwoezcgHQeULT59M5",
"description": "Flash mint"
}
}
}
}
}],
"addr_test1qp9mj7vnenx4v99hw7ztfq03n7dmmujpgtlyfjhhel9w67nk72usllcew208n60ym94xcptfrgytuy5apwp565x28jgsg0ztq3": [{
"policy_id": "18ed282beda4bec13226c427d4744d2642ba2cef404470b62ae184d8",
"asset_name": "Tango#003",
"quantity": 1,
"metadata": {
"721": {
"cdf7a949cca0d57a27f862d525e4d4c734c1d503cbc7f04c1ac2350e": {
"Tango#002": {
"name": "Tango #003",
"image": "ipfs://QmbFhLR5C6BmTW7apgDMVmGozLuEUZwoezcgHQeULT59M5",
"description": "Flash mint"
}
}
}
}
}]
},
"minting_script": {
"type": "all",
"scripts": [{
"type": "sig",
"keyHash": "1aabe8cdb1153e11c3363270fd11baef2ca758e56d9a0866e73f7dc5"
},
{
"type": "before",
"slot": 196536677
}
]
},
"change_address": "addr_test1qpemm54tmynjhuyw0qhzdpnras29c3pc8gxvc4afpsa3uwglmrag6mlare663x64ugkkv8nqhqg3z6u78xa49fq6wmts55h5y9"
}
const response = await txClient.buildTransaction(request);
const buildTx = response.result;
// sign tx
const keys = [
'xprv1gpn7d2h38j5ukpvmuz4mmrlgaprx6pcp53987ff8lkuqk2ztd4p2fdfpap4ev98hg3uj8kd36wzva3av8r776ke50dhhkm2ktpca83tj46xlscy6d7qga23ql4nn7z2hl9a4r3gqgpt6n7glv57nwkf80ypl5j63', // your spending/input keys
'xprv1zpetq5ux75u7gsryanjp7f4l39znck0x45myxrkwqh2qr8cxne9ndrt2g28kaqgc3s0er09haaxflwzljcgytmhklswtas42kd0ajsvz404dkvjje5j6wh3envwd25w728vzwzv46mlf9nzz0683ncju9y04jv8j' // minting script keys
];
const signed = await txClient.signTransaction({
keys,
tx: buildTx.tx
});
// submit tx
const txId = (await txClient.submitTransaction({
tx: signed
})).result.tx_id;
console.log("txid", txId);
try {
let txdata= await tc.transaction().getTransaction(txId);
console.log(txdata);
} catch (error) {
console.log(error);
}
}
mint()
Last modified 2mo ago