From b90da4992dd5098edf3653d0669647bb394d3362 Mon Sep 17 00:00:00 2001 From: Doug Richar Date: Thu, 8 May 2025 00:05:27 -0400 Subject: [PATCH 1/2] feat(sdk): add optional reservedFor param to NFD minting Add optional `reservedFor` parameter to `NfdMintParams` interface, allowing NFDs to be minted and reserved for a different address than the buyer. If not specified, the behavior remains unchanged and uses the buyer's address. --- packages/sdk/src/modules/minting.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/sdk/src/modules/minting.ts b/packages/sdk/src/modules/minting.ts index 9abe0df..a75580b 100644 --- a/packages/sdk/src/modules/minting.ts +++ b/packages/sdk/src/modules/minting.ts @@ -1,4 +1,5 @@ import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount' +import { isValidAddress } from 'algosdk' import { canMintSegment, @@ -25,6 +26,11 @@ export interface NfdMintParams { * Number of years until expiration (1-20) */ years: number + + /** + * Optional address to reserve the NFD for. If not provided, the buyer's address will be used. + */ + reservedFor?: string } /** @@ -264,7 +270,7 @@ export class MintingModule extends BaseModule { ) } - const { buyer: buyerAddr, years: numYears } = params + const { buyer: buyerAddr, years: numYears, reservedFor } = params // Validate years parameter if (numYears <= 0) { @@ -275,6 +281,11 @@ export class MintingModule extends BaseModule { throw new Error('Years must be an integer') } + // Validate reservedFor address + if (reservedFor && !isValidAddress(reservedFor)) { + throw new Error('Invalid reservedFor address') + } + // Get constraints to determine max years allowed let maxYearsAllowed = 20 // Default fallback try { @@ -328,7 +339,7 @@ export class MintingModule extends BaseModule { args: { purchaseTxn: paymentTxn, nfdName, - reservedFor: buyerAddr, + reservedFor: reservedFor || buyerAddr, linkOnMint: false, }, extraFee: AlgoAmount.MicroAlgos(extraFee), From 63242c2e31b65f48f57fb76c1db71808f9f0e5d9 Mon Sep 17 00:00:00 2001 From: Doug Richar Date: Thu, 8 May 2025 00:09:51 -0400 Subject: [PATCH 2/2] feat(example): add reservedFor field to NFD minting example Add input field to allow specifying an optional `reservedFor` address when minting an NFD in the example app. This demonstrates the new SDK capability to mint NFDs that are reserved for a different address than the buyer. --- examples/mint/src/App.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/examples/mint/src/App.tsx b/examples/mint/src/App.tsx index 0c6106e..7a38eb7 100644 --- a/examples/mint/src/App.tsx +++ b/examples/mint/src/App.tsx @@ -13,6 +13,7 @@ const nfd = NfdClient.testNet() export function App() { const [nfdName, setNfdName] = useState('') const [years, setYears] = useState(1) + const [reservedFor, setReservedFor] = useState('') const [nfdData, setNfdData] = useState(null) const [quoteData, setQuoteData] = useState(null) const [error, setError] = useState('') @@ -27,6 +28,12 @@ export function App() { setNfdName(e.target.value) } + const handleReservedForChange = (e: React.ChangeEvent) => { + setQuoteData(null) + setNfdData(null) + setReservedFor(e.target.value) + } + const handleGetQuote = async (e: React.FormEvent) => { e.preventDefault() setError('') @@ -78,6 +85,7 @@ export function App() { .mint(quote.nfdName, { buyer: quote.buyer, years: quote.years, + ...(reservedFor.trim() && { reservedFor: reservedFor.trim() }), }) setNfdData(mintedNfd) @@ -139,6 +147,20 @@ export function App() { ))} + +
+ + +