Skip to content

Commit

Permalink
Fix server minting on simple token drop (#134)
Browse files Browse the repository at this point in the history
* Fix server minting on simple token drop

* Max duration config

* max duration
  • Loading branch information
SurgeCode authored Feb 16, 2024
1 parent a0ab984 commit 2606bf1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
12 changes: 0 additions & 12 deletions simple-token-drop/src/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",

}
23 changes: 18 additions & 5 deletions simple-token-drop/src/app/serverMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {

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}`)
Expand Down Expand Up @@ -57,3 +59,14 @@ export const connect = async (

return account;
};

export const serverMintArgs = (accountId: string): NearContractCall<MintArgsResponse> => {
return mint({
contractAddress: NFT_CONTRACT,
ownerId: accountId,
metadata: {
media: MEDIA_URL,
reference: REFERENCE_URL
}
})
}
7 changes: 7 additions & 0 deletions simple-token-drop/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"functions": {
"src/app/*": {
"maxDuration": 60
}
}
}

0 comments on commit 2606bf1

Please sign in to comment.