Cardinal
Search…
⌃K

Create and Retrieve a Ruleset

Create a Ruleset

1
// Imports
2
import { Connection, Keypair, Transaction } from "@solana/web3.js";
3
import { findRulesetId, createInitRulesetInstruction } from "@cardinal/creator-standard";
4
import { executeTransaction } from "../utils"; // Find this function in the setup section
5
import * as anchor from "@project-serum/anchor";
6
7
// Setup
8
const wallet = Keypair.fromSecretKey(
9
anchor.utils.bytes.bs58.decode("wallet secret key")
10
); // your wallet's secret key
11
const connection = new Connection("mainnet-beta");
12
const transaction = new Transaction();
13
14
// Create a ruleset transaction
15
const rulesetId = findRulesetId("YOUR_RULESET_NAME");
16
transaction.add(
17
createInitRulesetInstruction(
18
{
19
ruleset: rulesetId,
20
authority: wallet.publicKey,
21
payer: wallet.publicKey,
22
},
23
{
24
initRulesetIx: {
25
name: params.name,
26
collector: wallet.publicKey,
27
disallowedAddresses: [],
28
allowedPrograms: [],
29
},
30
}
31
)
32
);
33
34
// Execute transaction
35
txid = await executeTransaction(
36
connection,
37
transaction,
38
new anchor.Wallet(wallet)
39
);

Retrieve a Ruleset

// Imports
import { findRulesetId,Ruleset } from "@cardinal/creator-standard";
import { Connection } from "@solana/web3.js";
// Setup
const connection = new Connection("mainnet-beta");
// Retrieve a ruleset
const rulesetId = findRulesetId("ruleset-name");
const ruleset = await Ruleset.fromAccountAddress(connection, rulesetId);
// Use ruleset information
console.log(ruleset.name);
console.log(ruleset.allowedPrograms);