Submitted to the 2023 Sandstorm Hackathon. Application available: sandstorm.md
Mint and Drop an NFT after Verifying a Specific Solana Event has occurred
This is a serverless function that handles a POST request from Helius on Vercel using Next.js. The function:
- Validates and authorizes the
POSTrequest - Verifies that the type of transaction received matches what was expected (in this case 'BURN').
- It extracts the
tokenTransferarray from the body, and verifies that the tokens burned is greater than theMIN_BURNconstant. - If the amount of tokens burned is greater than the
MIN_BURNconstant, we send a call to CrossMint to mint an NFT to the burner orpyro.
Note, the front end here is really is just a tool to let ppl easily burn tokens. There's no link between the FE/BE. So you're welcome to play around with the FE, but the fun stuff is in
pages/api/burn.ts.
- Clone from GH.
- Rename
.env.exampleto.envand update the variables. \AUTH_CODEis self generated (i like solana keygen-grind to find something secure)CROSS_MINTenvs require a dev account from CrossMintDISCORDkeys are available via the Developer Portal-
- NOTE: You can disable DISCORD BOT by setting
const NOTIFY_DISCORD = falseinpages/api/burn.ts, in which case you shouldn't need these keys
- NOTE: You can disable DISCORD BOT by setting
-
- You'll need a Helius WebHook. At present this repo is only really indexed for the
Enhanced TransactiontypeBURN. The verification component is pretty modular and could easily be replaced with some other Tx Type and different success criteria. You'll need to wait to deploy the webhook until after you've launched your server. - Modify NFT rewards/metadata to your liking.
You should be able to test things out. Install dependencies and launch the app:
yarnyarn dev- Out the gate, you should be able to use
utils/samples/samplePOST.mdto run acurlcommand in a seperate terminal--this should effectively simulate recieving aPOSTrequest from the WebHook. Just make sure you're sending the request to the right path (in my case,http://localhost:3000/api/burn) You should see something like this in your server terminal:
Requesting NFT Mint:
- Pyro: Cw9P...4J1E
- Burn: 10,055,679 $BONK
- TxId: JWSn...JoDR
- CMID: w44177a9-02e9-4d04-a5ce-de7d5739d5bx
โ
Mint: arGbzUJQ1vTmjqPdDTqXsuqPxLQb1MGkUX5qTXt483Kx
โ
DCRD: ๐ค Connection Established
โ
DCRD: Message sent to server
โ
DCRD: ๐ค Connection destroyedTo get the feed from Helius, you need to push your component to a serverless function hosting provider. I used Vercel. I note some issues/limitations below, especially on their free plan.
At present (Jan 21, 2023):
- Webhooks:
- BURN Feed does not include inner tx Burns (e.g., burns associated with a Candy Machine mint)
- BURN Feed does not include BurnChecked tx's
- Vercel:
- Base plan is limited to 10s executions (which is only enough time to send a CM request)
- Pro plan is limited to 60s which is sufficient MOST of the time but I have seen some executions time out
- Future phases will have to explore alternatives
- Note: The Serverless Function logs will automatically be cut-off if the total size reaches over 4KB. This will require a log drain for future use
- CM:
- I don't believe metadata currently uses Metaplex's latest standard. I think the lack of
properties.filesfor the img file causes the NFT to not render on all platforms (e.g., Solana Explorer)
- I don't believe metadata currently uses Metaplex's latest standard. I think the lack of