Skip to content

Commit

Permalink
feature: fix #125 #126 to allow for extra image in metadata and to mo…
Browse files Browse the repository at this point in the history
…ve image preview out of traits
  • Loading branch information
newbreedofgeek committed Apr 6, 2024
1 parent aa56e70 commit 0e55c6f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,13 @@ Items below marked "required" are the "minimum" required for it to be compatible
```json
{
"description": "Data NFT description", // required
"data_preview_url": "https://previewdata.com",
"bonus_media_img": "ipfs://imgCID",
"attributes": [
{
"trait_type": "Creator", // required
"value": "creator address"
},
{
"trait_type": "Data Preview URL", // required
"value": "https://previewdata.com"
},
{
"trait_type": "extra trait",
"value": "extra trait value"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itheum/sdk-mx-data-nft",
"version": "3.0.0",
"version": "3.1.0-alpha.1",
"description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
25 changes: 17 additions & 8 deletions src/common/mint-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ export function createIpfsMetadata(
datasetTitle: string,
datasetDescription: string,
dataNFTStreamPreviewUrl: string,
address: string
address: string,
bonusNFTMediaImgUrl?: string
) {
const metadata = {
const metadata: Record<string, any> = {
description: `${datasetTitle} : ${datasetDescription}`,
data_preview_url: dataNFTStreamPreviewUrl,
attributes: [] as object[]
};
// if we have bonusNFTMediaImgUrl, we put that as a top level attribute as well
if (bonusNFTMediaImgUrl && bonusNFTMediaImgUrl.trim() !== '') {
metadata['bonus_media_img'] = bonusNFTMediaImgUrl.trim().toLowerCase();
}
const attributes = traits
.split(',')
.filter((element) => element.trim() !== '');
Expand All @@ -76,10 +82,11 @@ export function createIpfsMetadata(
const trait = { trait_type: key.trim(), value: value.trim() };
metadataAttributes.push(trait);
}
metadataAttributes.push({
trait_type: 'Data Preview URL',
value: dataNFTStreamPreviewUrl
});
//// This should not be a trait as it will pollute the trait filters on NFT marketplaces
// metadataAttributes.push({
// trait_type: 'Data Preview URL',
// value: dataNFTStreamPreviewUrl
// });
metadataAttributes.push({ trait_type: 'Creator', value: address });
metadata.attributes = metadataAttributes;
return metadata;
Expand All @@ -90,7 +97,8 @@ export async function createFileFromUrl(
datasetTitle: string,
datasetDescription: string,
dataNFTStreamPreviewUrl: string,
address: string
address: string,
bonusNFTMediaImgUrl?: string
) {
let res: any = '';
let data: any = '';
Expand All @@ -105,7 +113,8 @@ export async function createFileFromUrl(
datasetTitle,
datasetDescription,
dataNFTStreamPreviewUrl,
address
address,
bonusNFTMediaImgUrl
);
const _traitsFile = new File([JSON.stringify(traits)], 'metadata.json', {
type: 'application/json'
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export async function checkTraitsUrl(traitsUrl: string) {
throw new ErrMissingTrait(traits.attributes);
}

const requiredTraits = ['Creator', 'Data Preview URL'];
const requiredTraits = ['Creator'];
const traitsAttributes = traits.attributes;

for (const requiredTrait of requiredTraits) {
Expand Down
8 changes: 6 additions & 2 deletions src/nft-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export class NftMinter extends Minter {
* - nftStorageToken: the nft storage token to be used to upload the image and metadata to IPFS
* - antiSpamTokenIdentifier: the anti spam token identifier to be used for the minting
* - antiSpamTax: the anti spam tax to be set for the Data NFT-FT with decimals. Needs to be greater than 0 and should be obtained in real time via {@link viewMinterRequirements} prior to calling mint.
* - bonusNFTMediaImgUrl [optional] a bonus media image URL you can send in if needed.
*/
async mint(
senderAddress: IAddress,
Expand All @@ -175,14 +176,16 @@ export class NftMinter extends Minter {
nftStorageToken?: string;
antiSpamTokenIdentifier?: string;
antiSpamTax?: BigNumber.Value;
bonusNFTMediaImgUrl?: string;
}
): Promise<Transaction> {
const {
imageUrl,
traitsUrl,
nftStorageToken,
antiSpamTokenIdentifier,
antiSpamTax
antiSpamTax,
bonusNFTMediaImgUrl
} = options ?? {};

// deep validate all mandatory URLs
Expand Down Expand Up @@ -215,7 +218,8 @@ export class NftMinter extends Minter {
datasetTitle,
datasetDescription,
dataPreviewUrl,
senderAddress.bech32()
senderAddress.bech32(),
bonusNFTMediaImgUrl
);

const {
Expand Down
8 changes: 6 additions & 2 deletions src/sft-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export class SftMinter extends Minter {
* - imageUrl: the URL of the image for the Data NFT
* - traitsUrl: the URL of the traits for the Data NFT
* - nftStorageToken: the nft storage token to be used to upload the image and metadata to IPFS
* - bonusNFTMediaImgUrl a bonus media image URL you can send in if needed.
*
*/
async mint(
Expand All @@ -249,9 +250,11 @@ export class SftMinter extends Minter {
imageUrl?: string;
traitsUrl?: string;
nftStorageToken?: string;
bonusNFTMediaImgUrl?: string;
}
): Promise<Transaction> {
const { imageUrl, traitsUrl, nftStorageToken } = options ?? {};
const { imageUrl, traitsUrl, nftStorageToken, bonusNFTMediaImgUrl } =
options ?? {};

const tokenNameValidator = new StringValidator()
.notEmpty()
Expand Down Expand Up @@ -320,7 +323,8 @@ export class SftMinter extends Minter {
datasetTitle,
datasetDescription,
dataPreviewUrl,
senderAddress.bech32()
senderAddress.bech32(),
bonusNFTMediaImgUrl
);

const {
Expand Down

0 comments on commit 0e55c6f

Please sign in to comment.