Step 6 - Set Up the /api Folder + Magmar Routes

In this step we wire up every server-side call your dApp needs. You’ll create four HTTP endpoints in /app/api that rely on the Magmar SDK stack.

Endpoint
Purpose
Magmar module

/api/get-signer

Deterministically derive the owner address behind a Smart-Contract Wallet (SCW)

@magmar/aa-core

/api/get-user-nfts

Fetch NFTs owned by an SCW for dashboard display

magmar-nft-sdk

/api/mint-nft-user-op

Send a sponsored UserOperation that mints an NFT to the user’s SCW

@magmar/aa-core + @magmar/aa-paymaster

/api/get-user

Retrieve a user’s encrypted private key from Userbase (demo only)

axios

6.1 Install Magmar Server-Side Dependencies

npm i @magmar/aa-core @magmar/aa-paymaster magmar-nft-sdk axios

6.2 Project Structure

/app
  /api
    /get-signer
      route.ts
    /get-user-nfts
      route.ts
    /mint-nft-user-op
      route.ts
    /get-user
      route.ts

6.3 /get-signer/route.ts


6.4 /get-user-nfts/route.ts


6.5 /mint-nft-user-op/route.ts (sponsored mint)


6.6 /get-user/route.ts (demo-only key fetch)


6.7 Update .env.local


Result

  • /sign-up and /login now compile without red errors

  • A new user can register, mint an NFT, and view it all gas-free using Magmar Paymaster sponsorship

Last updated