From 9694bb972b9372cf9b6811b8062b66ec6558dbf8 Mon Sep 17 00:00:00 2001 From: TheChronicMonster Date: Thu, 15 Sep 2022 16:35:04 -0500 Subject: [PATCH] algo mints --- examples/simple-nft-minter/index.mjs | 43 ++++++++++++++++++++++++++++ examples/simple-nft-minter/index.rsh | 1 + 2 files changed, 44 insertions(+) create mode 100644 examples/simple-nft-minter/index.mjs create mode 100644 examples/simple-nft-minter/index.rsh diff --git a/examples/simple-nft-minter/index.mjs b/examples/simple-nft-minter/index.mjs new file mode 100644 index 0000000000..e8355b865a --- /dev/null +++ b/examples/simple-nft-minter/index.mjs @@ -0,0 +1,43 @@ +import { loadStdlib } from '@reach-sh/stdlib'; +const stdlib = loadStdlib(process.env); + +const startingBalance = stdlib.parseCurrency(100000); + +const [minter, receiver] = await stdlib.newTestAccounts(2, startingBalance); + +const gasLimit = 5000000; +minter.setGasLimit(gasLimit); +receiver.setGasLimit(gasLimit); + +const mintAddr = minter.getAddress(); +console.log(`Your address is ${mintAddr}`); +const recAddr = receiver.getAddress(); +console.log(`receiver's address is ${recAddr}`); + +const minterAddrFormat = await stdlib.formatAddress(minter); +console.log(`The minter's formatted address is ${minterAddrFormat}`); +const receiverAddrFormat = await stdlib.formatAddress(receiver); +console.log(`The receiver's formatted address is ${receiverAddrFormat}`); + +const fmt = (x) => stdlib.formatCurrency(x, 4); +const getBal = async (who) => fmt(await stdlib.balanceOf(who)); +const bal = await getBal(minter); +console.log(`Minter starting balance: ${bal}.`); + +console.log(`Creating the NFT`); +const theNFT = await stdlib.launchToken(minter, "nftName", "SYM", { supply: 1, url: "https://reach.sh", clawback: null, freeze: null, defaultFrozen: false, reserve: null, note: Uint8Array[1]}); +const nftId = theNFT.id; + +const [preAmtNFT] = await stdlib.balancesOf(minter, [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); +console.log(`NFT transfer made from minter to receiver`); + +const postBal = await getBal(minter); +console.log(`Minter balance after transfer: ${postBal}.`); + +const [postAmtNFT] = await stdlib.balancesOf(receiver, [nftId]); +console.log(`Receiver has ${postAmtNFT} of the NFT`); \ No newline at end of file diff --git a/examples/simple-nft-minter/index.rsh b/examples/simple-nft-minter/index.rsh new file mode 100644 index 0000000000..7eee8baeb1 --- /dev/null +++ b/examples/simple-nft-minter/index.rsh @@ -0,0 +1 @@ +'reach 0.1' \ No newline at end of file