1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Solana Actions Example
*/
import {
ActionPostResponse,
ACTIONS_CORS_HEADERS,
createPostResponse,
ActionGetResponse,
ActionPostRequest,
} from "@solana/actions";
import { clusterApiUrl } from "@solana/web3.js";
import { createTree } from "@metaplex-foundation/mpl-bubblegum";
import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import {
createNoopSigner,
createSignerFromKeypair,
generateSigner,
publicKey,
PublicKey,
signerIdentity,
signerPayer,
} from "@metaplex-foundation/umi";
export const GET = async (req: Request) => {
const payload: ActionGetResponse = {
title: "Actions Example - Create a merkle tree",
icon: new URL("/solana_devs.jpg", new URL(req.url).origin).toString(),
description:
"Create a single state compression tree on solana for use with compressed NFTs",
label: "Send Memo",
links: {
actions: [
{
label: "Create Tree",
href: "/api/actions/create-tree?depth={depth}&buffer={buffer}&canopy={canopy}",
parameters: [
{
name: "depth",
required: true,
label: "Max depth for the tree",
},
{
name: "buffer",
required: true,
label: "Max buffer size for the tree",
},
{
name: "canopy",
required: true,
label: "Canopy depth for the tree",
},
],
},
],
},
};
return Response.json(payload, {
headers: ACTIONS_CORS_HEADERS,
});
};
// DO NOT FORGET TO INCLUDE THE `OPTIONS` HTTP METHOD
// THIS WILL ENSURE CORS WORKS FOR BLINKS
export const OPTIONS = GET;
export const POST = async (req: Request) => {
try {
const body: ActionPostRequest = await req.json();
let account: PublicKey;
try {
// account = new PublicKey(body.account);
account = publicKey(body.account);
} catch (err) {
return new Response('Invalid "account" provided', {
status: 400,
headers: ACTIONS_CORS_HEADERS,
});
}
const url = new URL(req.url);
// init the tree config values
const treeConfig = {
maxBufferSize: 0,
canopyDepth: 0,
maxDepth: 0,
};
try {
let depth = url.searchParams.get("depth");
let canopy = url.searchParams.get("canopy");
let buffer = url.searchParams.get("buffer");
if (!!depth) treeConfig.maxDepth = parseInt(depth);
if (!!canopy) treeConfig.canopyDepth = parseInt(canopy);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 2, 2024