Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacqueline Zhang committed May 28, 2024
1 parent db79537 commit 65af872
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function captureConsoleLogs(consoleLogs:string[]){
return consoleLogs;
};

export async function mintNFT(WALLET_PRIVATE_KEY: Hex): Promise<string> {
export async function mintNFT(WALLET_PRIVATE_KEY: Hex, NFT_COLLECTION_ADDRESS?: Address): Promise<string> {
const account = privateKeyToAccount(WALLET_PRIVATE_KEY as Address);
const baseConfig = {
chain: chainId,
Expand All @@ -58,9 +58,10 @@ export async function mintNFT(WALLET_PRIVATE_KEY: Hex): Promise<string> {
};

const requestArgs = {
address: nftContractAddress as Address,
address: NFT_COLLECTION_ADDRESS || nftContractAddress,
functionName: 'mint',
args: [account.address],
account: walletClient.account,
abi: [contractAbi]
};

Expand Down Expand Up @@ -110,7 +111,7 @@ export async function isRegistered(ipId: Address): Promise<boolean> {
return Boolean(result);
};

export async function mintNFTWithTokenID(WALLET_PRIVATE_KEY: Hex, id: number): Promise<string> {
export async function mintNFTWithTokenID(WALLET_PRIVATE_KEY: Hex, id: number, NFT_COLLECTION_ADDRESS?: Address): Promise<string> {
const account = privateKeyToAccount(WALLET_PRIVATE_KEY as Address);
const baseConfig = {
chain: chainId,
Expand All @@ -135,9 +136,10 @@ export async function mintNFTWithTokenID(WALLET_PRIVATE_KEY: Hex, id: number): P
};

const requestArgs = {
address: nftContractAddress as Address,
address: NFT_COLLECTION_ADDRESS || nftContractAddress,
functionName: 'mintId',
args: [account.address, BigInt(id)],
account: walletClient.account,
abi: [contractAbi]
};

Expand Down Expand Up @@ -294,25 +296,25 @@ export async function getLatestTokenId(): Promise<number> {
return Number(latestTokenId);
};

export async function mintNFTWithRetry(WALLET_PRIVATE_KEY: Hex): Promise<string> {
export async function mintNFTWithRetry(WALLET_PRIVATE_KEY: Hex, NFT_COLLECTION_ADDRESS?: Address): Promise<string> {
let tokenId: string = '';

for (let i = 0; i < 3; i++) {
try {
tokenId = await mintNFT(WALLET_PRIVATE_KEY);
tokenId = await mintNFT(WALLET_PRIVATE_KEY, NFT_COLLECTION_ADDRESS);
break;
} catch (error) {
if (i === 1) {
try{
const latestTokenId = await getLatestTokenId();
tokenId = await mintNFTWithTokenID(WALLET_PRIVATE_KEY, Number(latestTokenId) + 1);
tokenId = await mintNFTWithTokenID(WALLET_PRIVATE_KEY, Number(latestTokenId) + 1, NFT_COLLECTION_ADDRESS);
break;
} catch (error) {
tokenId = '';
}
}
}
}
};
};
};
};

return tokenId;
};
Expand Down Expand Up @@ -343,5 +345,4 @@ export function processResponse(response: any):{ [key: string]: string | bigint
}
});
return responseJson;
};

};

0 comments on commit 65af872

Please sign in to comment.