-
Notifications
You must be signed in to change notification settings - Fork 8
miniapp: zora minter #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a95596
miniapp(zora-minter): initial commit
stephancill 44168a6
feat: add intermediate states for sendethtransaction action
stephancill 2053d03
chore(docs): add context and send tx action resolver to integrate exa…
stephancill 8d79de7
chore(zora-minter): remove debugging state
stephancill f9bc344
chore(docs): fix syntax errors
stephancill e68947f
fix(example): useMemo for embed context and resolvers
stephancill 828563e
fix: update yarn.lock
stephancill 5bbee7a
chore(miniapp): exclude from miniapp registry
stephancill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@mod-protocol/core": minor | ||
| --- | ||
|
|
||
| feat(core): miniapp permissions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| "@mod-protocol/react": minor | ||
| "@mod-protocol/core": minor | ||
| "@mod-protocol/miniapp-registry": patch | ||
| "@miniapps/zora-nft-minter": patch | ||
| "web": patch | ||
| "api": patch | ||
| --- | ||
|
|
||
| feat: add `SENDETHTRANSACTION` action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { createClient, reservoirChains } from "@reservoir0x/reservoir-sdk"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { createWalletClient, http } from "viem"; | ||
| import * as viemChains from "viem/chains"; | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| try { | ||
| const searchParams = request.nextUrl.searchParams; | ||
| const taker = searchParams.get("taker"); | ||
| const itemId = searchParams.get("itemId"); // CAIP-19 ID | ||
| const referrer = searchParams.get("referrer") || undefined; | ||
|
|
||
| // Extract contract, type, and chain ID from itemId | ||
| // e.g. chain://eip155:1/erc721:0xa723a8a69d9b8cf0bc93b92f9cb41532c1a27f8f/11 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. helpful examples! |
||
| // e.g. chain://eip155:7777777/erc1155:0xd4fbb6ee19708983b4a2ba7e6e627b94da690a3e/1 | ||
| // e.g. chain://eip155:8453/erc721:0x029B142Fe0cEb2e50e02C319647CE9A7657c2B59 | ||
| // e.g. chain://eip155:1/erc721:0x87C9ffD26ADe3fDAEf35cddB8c1ff86B6355a263 (allowlist) | ||
| // e.g. chain://eip155:10/erc721:0xEc5cF8551C812A9fa2DDF3B0741AEeF72314B25d | ||
| // e.g. chain://eip155:7777777/erc1155:0x4afa7992f876225cda4d503d0d1a3125348ce35b/1 | ||
| const [, , prefixAndChainId, prefixAndContractAddress, tokenId] = | ||
| itemId.split("/"); | ||
|
|
||
| let [, chainId] = prefixAndChainId.split(":"); | ||
| const [type, contractAddress] = prefixAndContractAddress.split(":"); | ||
|
|
||
| let buyTokenPartial: { token?: string; collection?: string }; | ||
| if (type === "erc721") { | ||
| buyTokenPartial = { collection: contractAddress }; | ||
| } else if (type === "erc1155") { | ||
| buyTokenPartial = { token: `${contractAddress}:${tokenId}` }; | ||
| } | ||
|
|
||
| const reservoirChain = [...Object.values(reservoirChains)].find( | ||
| (chain) => chain.id === parseInt(chainId) | ||
| ); | ||
|
|
||
| const viemChain: viemChains.Chain = [...Object.values(viemChains)].find( | ||
| (chain) => chain.id === parseInt(chainId) | ||
| ); | ||
|
|
||
| if (!reservoirChain) { | ||
| throw new Error("Unsupported chain"); | ||
| } | ||
|
|
||
| // Create reservoir client with applicable chain | ||
| const reservoirClient = createClient({ | ||
| chains: [{ ...reservoirChain, active: true }], | ||
| }); | ||
|
|
||
| const wallet = createWalletClient({ | ||
| account: taker as `0x${string}`, | ||
| transport: http(), | ||
| chain: viemChain, | ||
| }); | ||
|
|
||
| const res = await reservoirClient.actions.buyToken({ | ||
| items: [{ ...buyTokenPartial, quantity: 1, fillType: "mint" }], | ||
| options: { | ||
| referrer, | ||
| }, | ||
| wallet, | ||
| precheck: true, | ||
| onProgress: () => void 0, | ||
| }); | ||
|
|
||
| if (res === true) { | ||
| return NextResponse.json(res); | ||
| } | ||
|
|
||
| const mintTx = res.steps.find((step) => step.id === "sale").items[0]; | ||
|
|
||
| return NextResponse.json({ | ||
| ...mintTx, | ||
| chainId, | ||
| explorer: viemChain.blockExplorers.default, | ||
| }); | ||
| } catch (err) { | ||
| return NextResponse.json( | ||
| { message: err.response?.data?.message || err.message }, | ||
| { status: err.status ?? 400 } | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| NEXT_PUBLIC_API_URL="http://localhost:3001/api" | ||
| NEXT_PUBLIC_API_URL="http://localhost:3001/api" | ||
| NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.