Skip to content

Commit

Permalink
feature: on solana mininting, we allow the user to send their own cus…
Browse files Browse the repository at this point in the history
…tom ipfs gateway to see if this solves the image not appearing issue
  • Loading branch information
newbreedofgeek committed Nov 27, 2024
1 parent 0521f53 commit 8c2d150
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
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.8.0-alpha.16",
"version": "3.8.0-alpha.17",
"description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
11 changes: 8 additions & 3 deletions src/cnft-sol-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class CNftSolMinter extends MinterSol {
* - imgGenSet: [optional] the custom series layer set to influence the image generation service
* - signatureNonce: [optional] a recent nonce from the marshal network that will be signed to produce solSignature
* - solSignature: [optional] a solana signature of signatureNonce to prove creatorAddress ownership
* - useThisCustomIPFSGateway: [optional] a custom ipfs gateway to use for the img and json. where the CID goes in a {insertCIDHere} placeholder e.g. https://gateway.pinata.cloud/ipfs/{insertCIDHere}.
*
*/
async mint(
Expand All @@ -62,6 +63,7 @@ export class CNftSolMinter extends MinterSol {
imgGenSet?: string;
signatureNonce?: string;
solSignature?: string;
useThisCustomIPFSGateway?: string;
}
): Promise<{
imageUrl: string;
Expand All @@ -81,7 +83,8 @@ export class CNftSolMinter extends MinterSol {
imgGenBg,
imgGenSet,
signatureNonce,
solSignature
solSignature,
useThisCustomIPFSGateway
} = options ?? {};

const tokenNameValidator = new StringValidator()
Expand Down Expand Up @@ -160,7 +163,8 @@ export class CNftSolMinter extends MinterSol {

const { imageOnIpfsUrl: imgOnIpfsUrl } = await storeToIpfsOnlyImg(
nftStorageToken,
_imageFile
_imageFile,
useThisCustomIPFSGateway
);

if (!imgOnIpfsUrl || imgOnIpfsUrl === '') {
Expand All @@ -182,7 +186,8 @@ export class CNftSolMinter extends MinterSol {

const { metadataIpfsUrl } = await storeToIpfsFullSolCNftMetadata(
nftStorageToken,
cNftMetadataContent
cNftMetadataContent,
useThisCustomIPFSGateway
);

if (!metadataIpfsUrl || metadataIpfsUrl === '') {
Expand Down
46 changes: 38 additions & 8 deletions src/common/mint-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export async function storeToIpfs(

export async function storeToIpfsFullSolCNftMetadata(
storageToken: string,
metadataStructureSolCNft: object
metadataStructureSolCNft: object,
useThisCustomIPFSGateway?: string
): Promise<{ metadataIpfsUrl: string }> {
try {
const metadataIpfsHash = await storeTraitsToIpfs(
Expand All @@ -71,9 +72,23 @@ export async function storeToIpfsFullSolCNftMetadata(
);

if (metadataIpfsHash) {
return {
metadataIpfsUrl: `https://ipfs.io/ipfs/${metadataIpfsHash}`
};
if (
useThisCustomIPFSGateway &&
useThisCustomIPFSGateway.includes('https://') &&
useThisCustomIPFSGateway.includes('{insertCIDHere}')
) {
// user wanted to use a custom gateway
return {
metadataIpfsUrl: useThisCustomIPFSGateway.replace(
'{insertCIDHere}',
metadataIpfsHash
)
};
} else {
return {
metadataIpfsUrl: `https://ipfs.io/ipfs/${metadataIpfsHash}`
};
}
} else {
return {
metadataIpfsUrl: ''
Expand All @@ -86,15 +101,30 @@ export async function storeToIpfsFullSolCNftMetadata(

export async function storeToIpfsOnlyImg(
storageToken: string,
image: Blob
image: Blob,
useThisCustomIPFSGateway?: string
): Promise<{ imageOnIpfsUrl: string }> {
try {
const imageHash = await storeImageToIpfs(image, storageToken);

if (imageHash) {
return {
imageOnIpfsUrl: `https://ipfs.io/ipfs/${imageHash}`
};
if (
useThisCustomIPFSGateway &&
useThisCustomIPFSGateway.includes('https://') &&
useThisCustomIPFSGateway.includes('{insertCIDHere}')
) {
// user wanted to use a custom gateway
return {
imageOnIpfsUrl: useThisCustomIPFSGateway.replace(
'{insertCIDHere}',
imageHash
)
};
} else {
return {
imageOnIpfsUrl: `https://ipfs.io/ipfs/${imageHash}`
};
}
} else {
return {
imageOnIpfsUrl: ''
Expand Down

0 comments on commit 8c2d150

Please sign in to comment.