Skip to content

Commit

Permalink
algo mints
Browse files Browse the repository at this point in the history
  • Loading branch information
TheChronicMonster committed Sep 15, 2022
1 parent 92772c3 commit 9694bb9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/simple-nft-minter/index.mjs
Original file line number Diff line number Diff line change
@@ -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`);
1 change: 1 addition & 0 deletions examples/simple-nft-minter/index.rsh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'reach 0.1'

0 comments on commit 9694bb9

Please sign in to comment.