Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/build
/scribble.log
/convert.log
/dev.log
/gen.log
/md
/secret.env
72 changes: 72 additions & 0 deletions examples/simple-nft-minter/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Reach, test } from '@reach-sh/stdlib';
const stdlib = new Reach(process.env, { REACH_NO_WARN: 'Y' });

const startingBalance = stdlib.parseCurrency(100);
const [minter, receiver] = await stdlib.newTestAccounts(2, startingBalance);
minter.setDebugLabel('Minter');
receiver.setDebugLabel('Receiver');

const gasLimit = 5000000;
if (stdlib.connector != 'ALGO') {
minter.setGasLimit(gasLimit) && receiver.setGasLimit(gasLimit)
};

const mintAddr = minter.getAddress();
console.log(`Minter's 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, tok) => tok ? (await stdlib.balanceOf(who, tok)) : fmt(await stdlib.balanceOf(who));

const logBalance = async (acc, tok) => {
Comment on lines +25 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In these two functions, you have an "acceptable" path on tok being undefined. I think it is kinder to use (who, tok = false), to better communicate to the reader that often you expect it to not be provided

const bal = await getBal(acc, tok);
const unit = tok ? 'of the NFT' : stdlib.standardUnit;
console.log(`${acc.getDebugLabel()} has ${bal} ${unit}.`);
return bal;
}

await logBalance(minter);

const name = (stdlib.connector == 'ALGO') ? "JPAlgos" : "JPals";
const symbol = (stdlib.connector == 'ALGO') ? "JPA" : "JPAL";

const opts = {
supply: 1,
url: "ipfs://bafybeigdyrzt5...", //asset url
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more compelling if you demonstrate actually creating it too. The same information that you're going to put in the Note field, you want to upload to IPFS.

This page has a little tutorial:

https://js.ipfs.tech/

under "Adding data to IPFS"

If you are nervous about including it in the code always or having our CI do it, etc, then at least make a little program on the side (or a way to run this program) and comment on it in your guide

c: null, // clawback
f: null, // freeze address
defaultFrozen: false,
reserve: null,
note: Uint8Array[1],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just undefined and I'm surprised it is not an error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you should use the ARC spec and have the note actually contain what it is supposed to

};

const mintNFT = async (minter, name, symbol, opts) => {
console.log(`Creating the NFT`);
const theNFT = await stdlib.launchToken(minter, name, symbol, opts);
console.log(theNFT);
return theNFT.id;
}

const transferNFT = async (minter, receiver, nftId, supply) => {
const preAmtNFT = await logBalance(minter, nftId);

if (stdlib.connector == 'ALGO') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should always do it and note that it does nothing on ETH

await receiver.tokenAccept(nftId);
console.log(`${receiver.getDebugLabel()} opted-in to NFT`);
};
await stdlib.transfer(minter, receiver, supply, nftId);
console.log(`${supply} ${symbol} transferred from ${minter.getDebugLabel()} to ${receiver.getDebugLabel()}`);

const postAmtNFT = await logBalance(receiver, nftId);
test.chk('NFT AMT', preAmtNFT, postAmtNFT);
}

const nftId = await mintNFT(minter, name, symbol, opts);
await transferNFT(minter, receiver, nftId, opts.supply);
await logBalance(minter);
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'
5 changes: 5 additions & 0 deletions examples/simple-nft-minter/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Verifying knowledge assertions
Verifying for generic connector
Verifying when ALL participants are honest
Verifying when NO participants are honest
Checked 0 theorems; No failures!