Skip to content

Commit

Permalink
feat: paramzd
Browse files Browse the repository at this point in the history
  • Loading branch information
TheChronicMonster committed Oct 12, 2022
1 parent f96e29b commit 33c9efa
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions examples/simple-nft-minter/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -24,40 +24,47 @@ 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);
console.log(`Receiver has ${postAmtNFT} of the NFT`);
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}.`);

0 comments on commit 33c9efa

Please sign in to comment.