From 33c9efa4e93de9875f7f4967d639ecd0cc032e6f Mon Sep 17 00:00:00 2001 From: TheChronicMonster Date: Wed, 12 Oct 2022 12:11:49 -0500 Subject: [PATCH] feat: paramzd --- examples/simple-nft-minter/index.mjs | 51 ++++++++++++++++------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/examples/simple-nft-minter/index.mjs b/examples/simple-nft-minter/index.mjs index 5c9f71e27c..a56c8240d7 100644 --- a/examples/simple-nft-minter/index.mjs +++ b/examples/simple-nft-minter/index.mjs @@ -6,8 +6,8 @@ const startingBalance = stdlib.parseCurrency(100); const [minter, receiver] = await stdlib.newTestAccounts(2, startingBalance); const gasLimit = 500000; -if (stdlib.connector == 'ETH') {minter.setGasLimit(gasLimit)}; -if (stdlib.connector == 'ETH') {receiver.setGasLimit(gasLimit)}; +if (stdlib.connector != 'ALGO') {minter.setGasLimit(gasLimit)}; +if (stdlib.connector != 'ALGO') {receiver.setGasLimit(gasLimit)}; const mintAddr = minter.getAddress(); console.log(`Your address is ${mintAddr}`); @@ -24,32 +24,38 @@ const getBal = async (who) => fmt(await stdlib.balanceOf(who)); const bal = await getBal(minter); console.log(`Minter starting balance: ${bal}.`); -const mintNFT = async () => { +const opts = { + supply: 1, + au: "ipfs://bafybeigdyrzt5...", //asset url + c: null, // clawback + f: null, // freeze address + defaultFrozen: false, + reserve: null, + note: Uint8Array[1], +}; + +const name = "JPAlgos"; +const symbol = "JPA"; + +const mintNFT = async (minter, name, symbol, opts = {supply: 1, au: "ipfs://bafybeigdyrzt5...", c: null, f: null, defaultFrozen: false, reserve: null, note: Uint8Array[1]}) => { console.log(`Creating the NFT`); - const theNFT = await stdlib.launchToken(minter, "JPalgos", "JPA", { - supply: 1, - au: "ipfs://placeholderQmYgEFqRkWvNZu7gfk9HDdh55bQbYyc16TF1zX58", //asset url - c: null, // clawback - f: null, // freeze address - defaultFrozen: false, - reserve: null, - note: Uint8Array[1], - }); - const nftId = await theNFT.id; - test.chk('NFT ID', nftId, theNFT.id); - - await transferNFT(nftId); - return await nftId; + const theNFT = await stdlib.launchToken(minter, name, symbol, opts); + console.log(theNFT); + return theNFT.id; } -const transferNFT = async (nftId) => { +const transferNFT = async (minter, receiver, nftId, supply) => { const preAmtNFT = await minter.balanceOf(nftId); console.log(`Minter has ${preAmtNFT} of the NFT`); - if (stdlib.connector == 'ALGO' && await receiver.tokenAccept(nftId)) {console.log(`Receiver opted-in to NFT`)}; - if (stdlib.connector == 'ALGO' && await receiver.tokenAccepted(nftId)) {console.log(`Token accepted`)}; - await stdlib.transfer(minter, receiver, 1, nftId); + if (stdlib.connector == 'ALGO' && await receiver.tokenAccept(nftId)) { + console.log(`Receiver opted-in to NFT` + )}; + if (stdlib.connector == 'ALGO' && await receiver.tokenAccepted(nftId)) { + console.log(`Token accepted` + )}; + await stdlib.transfer(minter, receiver, supply, nftId); console.log(`NFT transfer made from minter to receiver`); const postAmtNFT = await receiver.balanceOf(nftId); @@ -57,7 +63,8 @@ const transferNFT = async (nftId) => { test.chk('NFT AMT', preAmtNFT, postAmtNFT); } -await mintNFT(); +const nftId = await mintNFT(minter, name, symbol, opts); +await transferNFT(minter, receiver, nftId, opts.supply); const postBal = await getBal(minter); console.log(`Minter balance after transfer: ${postBal}.`); \ No newline at end of file