diff --git a/src/handlers/generate-erc721-permit.ts b/src/handlers/generate-erc721-permit.ts index 39ebced..569c273 100644 --- a/src/handlers/generate-erc721-permit.ts +++ b/src/handlers/generate-erc721-permit.ts @@ -68,9 +68,23 @@ export async function generateErc721PermitSignature( _userId = contextOrPermitPayload.userId; } else { const { NFT_MINTER_PRIVATE_KEY, NFT_CONTRACT_ADDRESS } = contextOrPermitPayload.env; + + _logger = contextOrPermitPayload.logger; + + if (!NFT_MINTER_PRIVATE_KEY) { + const errorMessage = "NFT minter private key is not defined"; + _logger.error(errorMessage); + throw new Error(errorMessage); + } + + if (!NFT_CONTRACT_ADDRESS) { + const errorMessage = "NFT contract address is not defined"; + _logger.error(errorMessage); + throw new Error(errorMessage); + } + const { evmNetworkId } = contextOrPermitPayload.config; const adapters = contextOrPermitPayload.adapters; - _logger = contextOrPermitPayload.logger; _nftContractAddress = NFT_CONTRACT_ADDRESS; _evmNetworkId = evmNetworkId; _nftMinterPrivateKey = NFT_MINTER_PRIVATE_KEY; @@ -102,12 +116,6 @@ export async function generateErc721PermitSignature( throw new Error("Provider is not defined"); } - if (!_nftContractAddress) { - const errorMessage = "NFT contract address is not defined"; - _logger.error(errorMessage); - throw new Error(errorMessage); - } - let adminWallet; try { diff --git a/src/types/env.ts b/src/types/env.ts index a816449..8994469 100644 --- a/src/types/env.ts +++ b/src/types/env.ts @@ -6,8 +6,8 @@ export const envSchema = T.Object({ GITHUB_TOKEN: T.String(), SUPABASE_URL: T.String(), SUPABASE_KEY: T.String(), - NFT_MINTER_PRIVATE_KEY: T.String(), - NFT_CONTRACT_ADDRESS: T.String(), + NFT_MINTER_PRIVATE_KEY: T.Optional(T.String()), + NFT_CONTRACT_ADDRESS: T.Optional(T.String()), }); export type Env = StaticDecode; diff --git a/tests/generate-erc721-permit.test.ts b/tests/generate-erc721-permit.test.ts index b65da8c..86b2638 100644 --- a/tests/generate-erc721-permit.test.ts +++ b/tests/generate-erc721-permit.test.ts @@ -117,7 +117,7 @@ describe("generateErc721PermitSignature", () => { it("should throw an error if NFT minter private key is not defined", async () => { delete process.env.NFT_MINTER_PRIVATE_KEY; - await expect(generateErc721PermitSignature(context, "123", "contribution")).rejects.toThrow("Failed to" + " instantiate wallet"); + await expect(generateErc721PermitSignature(context, "123", "contribution")).rejects.toThrow("NFT minter" + " private key" + " is not defined"); expect(context.logger.error).toHaveBeenCalled(); });