From 2606bf1e7b7da0c614bf32463cce5321f7c911fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Seco?= <52105707+SurgeCode@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:56:25 +0000 Subject: [PATCH] Fix server minting on simple token drop (#134) * Fix server minting on simple token drop * Max duration config * max duration --- simple-token-drop/src/app/constants.ts | 12 ------------ simple-token-drop/src/app/serverMint.ts | 23 ++++++++++++++++++----- simple-token-drop/vercel.json | 7 +++++++ 3 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 simple-token-drop/vercel.json diff --git a/simple-token-drop/src/app/constants.ts b/simple-token-drop/src/app/constants.ts index bcf6698a..931bbf08 100644 --- a/simple-token-drop/src/app/constants.ts +++ b/simple-token-drop/src/app/constants.ts @@ -23,15 +23,3 @@ export const CLIENT_MINT_ARGS = { } export const PROXY_CONTRACT = '0.drop.proxy.mintbase.testnet' - -export const SERVER_MINT_ARGS = { - contractAddress: PROXY_CONTRACT, - methodName: 'mint', - args: { - metadata: JSON.stringify({ reference: REFERENCE_URL, media: MEDIA_URL }), - nft_contract_id: NFT_CONTRACT - }, - gas: "200000000000000", - deposit: "10000000000000000000000", - - } diff --git a/simple-token-drop/src/app/serverMint.ts b/simple-token-drop/src/app/serverMint.ts index ce6347fe..4c989b91 100644 --- a/simple-token-drop/src/app/serverMint.ts +++ b/simple-token-drop/src/app/serverMint.ts @@ -4,25 +4,27 @@ import { Account, KeyPair, InMemorySigner } from "near-api-js"; import { InMemoryKeyStore } from "near-api-js/lib/key_stores"; import { FinalExecutionOutcome, JsonRpcProvider } from "near-api-js/lib/providers"; import BN from "bn.js"; -import { execute } from "@mintbase-js/sdk" +import { MintArgsResponse, NearContractCall, execute, mint } from "@mintbase-js/sdk" import { redirect } from 'next/navigation' -import { SERVER_MINT_ARGS, NETWORK, SERVER_WALLET_ID, SERVER_WALLET_PK, WALLET_AUTO_IMPORT_URL } from "./constants"; +import { NETWORK, SERVER_WALLET_ID, SERVER_WALLET_PK, WALLET_AUTO_IMPORT_URL, NFT_CONTRACT, MEDIA_URL, REFERENCE_URL } from "./constants"; export const serverMint = async (): Promise => { - + console.info("Server Action: Server Mint Called") //Create a new keypair, instantiate server wallet and create account with generated keypair const accountId = [...Array(7)].map(() => Math.random().toString(36)[2]).join('') + `.${SERVER_WALLET_ID}`; const newKeyPair = KeyPair.fromRandom('ed25519') const serverWallet: Account = await connect(); + await serverWallet.createAccount(accountId, newKeyPair.getPublicKey().toString(), new BN("0")) console.info("Server Action: Wallet created with account id: ", accountId) + const mintArgs = await serverMintArgs(accountId) //Execute mint with server wallet - await execute({ account: serverWallet }, SERVER_MINT_ARGS) as FinalExecutionOutcome + await execute({ account: serverWallet }, mintArgs) as FinalExecutionOutcome - console.info("Server Action: Executed mint with", SERVER_MINT_ARGS) + console.info("Server Action: Executed mint with", mintArgs) //@ts-ignore redirect(`${WALLET_AUTO_IMPORT_URL}${accountId}/${newKeyPair.secretKey}`) @@ -57,3 +59,14 @@ export const connect = async ( return account; }; + +export const serverMintArgs = (accountId: string): NearContractCall => { + return mint({ + contractAddress: NFT_CONTRACT, + ownerId: accountId, + metadata: { + media: MEDIA_URL, + reference: REFERENCE_URL + } + }) +} diff --git a/simple-token-drop/vercel.json b/simple-token-drop/vercel.json new file mode 100644 index 00000000..4e33348f --- /dev/null +++ b/simple-token-drop/vercel.json @@ -0,0 +1,7 @@ +{ + "functions": { + "src/app/*": { + "maxDuration": 60 + } + } + } \ No newline at end of file