Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/enable sft public mint #40

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions examples/substrate/use-sft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ pnpm call:mint
# transfer tokens(s)
pnpm call:transfer

# enable public minting
pnpm call:enablePublicMint

# public minting
pnpm call:publicMint

```
4 changes: 3 additions & 1 deletion examples/substrate/use-sft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"call:createToken": "pnpm call src/createToken.ts",
"call:updateToken": "pnpm call src/updateToken.ts",
"call:mint": "pnpm call src/mint.ts",
"call:transfer": "pnpm call src/transfer.ts"
"call:transfer": "pnpm call src/transfer.ts",
"call:enablePublicMint": "pnpm call src/enablePublicMint.ts",
"call:publicMint": "pnpm call src/publicMint.ts"
}
}
78 changes: 78 additions & 0 deletions examples/substrate/use-sft/src/enablePublicMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents";
import { formatEventData } from "@trne/utils/formatEventData";
import { sendExtrinsic } from "@trne/utils/sendExtrinsic";
import { withChainApi } from "@trne/utils/withChainApi";

const COLLECTION_ID = 1124;
const TOKEN_ID = 0;

/**
* Assuming a collection and a new token for a collection is created.
*
* Assumes the caller has XRP to pay for gas.
*/
withChainApi("local", async (api, caller, logger) => {
const tokenId = [COLLECTION_ID, TOKEN_ID] as [number, number];
const enabled = true;

logger.info(
{
parameters: {
tokenId,
enabled,
},
},
`create a "sft.togglePublicMint" extrinsic`
);

let extrinsic = api.tx.sft.togglePublicMint(tokenId, enabled);

logger.info(`dispatch extrinsic from caller/owner="${caller.address}"`);
let { result, extrinsicId } = await sendExtrinsic(extrinsic, caller, { log: logger });
let [createEvent] = filterExtrinsicEvents(result.events, ["Sft.PublicMintToggle"]);

logger.info(
{
result: {
extrinsicId,
blockNumber: result.blockNumber,
createEvent: formatEventData(createEvent.event),
},
},
"receive result"
);

// set mint fee for public minting

const paymentAsset = 2;
const price = 100;
const pricingDetails = [paymentAsset, price];
logger.info(
{
parameters: {
tokenId,
pricingDetails,
},
},
`create a "sft.togglePublicMint" extrinsic`
);

extrinsic = api.tx.sft.setMintFee(tokenId, pricingDetails);

logger.info(`dispatch extrinsic from caller/owner="${caller.address}"`);
const response = await sendExtrinsic(extrinsic, caller, { log: logger });
result = response.result;
extrinsicId = response.extrinsicId;
[createEvent] = filterExtrinsicEvents(result.events, ["Sft.MintPriceSet"]);

logger.info(
{
result: {
extrinsicId,
blockNumber: result.blockNumber,
createEvent: formatEventData(createEvent.event),
},
},
"receive result"
);
});
47 changes: 47 additions & 0 deletions examples/substrate/use-sft/src/publicMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents";
import { formatEventData } from "@trne/utils/formatEventData";
import { sendExtrinsic } from "@trne/utils/sendExtrinsic";
import { withChainApi } from "@trne/utils/withChainApi";

const COLLECTION_ID = 1124;
const TOKEN_ID = 0;

/**
* Assuming a collection, a new token for a collection is created and togglePublicMint is enabled for this (collection, tokenId) combination
*
* Assumes the caller has XRP to pay for gas and caller is not the collection owner.
*/
withChainApi("local", async (api, caller, logger) => {
const collectionId = COLLECTION_ID;
const tokenId = TOKEN_ID;
const tokenOwner = caller.address;
const quantity = 10;
const serialNumbers = [[tokenId, quantity]] as unknown as [[number, number]];

logger.info(
{
parameters: {
collectionId,
serialNumbers,
tokenOwner,
},
},
`create a "sft.mint" extrinsic`
);
const extrinsic = api.tx.sft.mint(collectionId, serialNumbers, tokenOwner);

logger.info(`dispatch extrinsic from caller="${caller.address}"`);
const { result, extrinsicId } = await sendExtrinsic(extrinsic, caller, { log: logger });
const [mintFeePaidEvent] = filterExtrinsicEvents(result.events, ["Sft.MintFeePaid"]);

logger.info(
{
result: {
extrinsicId,
blockNumber: result.blockNumber,
mintEvent: formatEventData(mintFeePaidEvent.event),
},
},
"receive result"
);
});
Loading