Complementary Examples of Guardian SDK used in conjunction with the Client to get your transactions out to the network and verified.
Runnable implementation of all the examples listed can be found here:
Edit the src/index.ts
file to run a specific example.
Before we get started we need to make sure that all of the required dependencies are installed.
yarn add @protokol/guardian-cryptoyarn add @protokol/client
yarn add @protokol/guardian-cryptoyarn add @protokol/client
yarn add @protokol/guardian-cryptoyarn add @protokol/client
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as GuardianTransactions } from "@protokol/guardian-crypto";export const guardianUserPermission = async () => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(GuardianTransactions.GuardianUserPermissionsTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.GuardianUserPermissionsBuilder().GuardianUserPermissions({groupNames: ["Test Guardian Permission Group"],allow: [{ transactionTypeGroup: 1, transactionType: 2 }],publicKey: Identities.PublicKey.fromPassphrase("This is my passphrase"),}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};
import { Identities, Managers, Transactions, Utils } from "@arkecosystem/crypto";import { ProtokolConnection } from "@protokol/client";import { Builders, Transactions as GuardianTransactions } from "@protokol/guardian-crypto";export const guardianGroupPermission = async (): Promise<any> => {// Configure manager and register transaction typeManagers.configManager.setFromPreset("testnet");Managers.configManager.setHeight(2);Transactions.TransactionRegistry.registerTransactionType(GuardianTransactions.GuardianGroupPermissionsTransaction);// Configure our API clientconst client = new ProtokolConnection("http://localhost:4003/api");const passphrase = "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire";// Step 1: Retrieve the nonce of the sender walletconst senderWallet = await client.api("wallets").get(Identities.Address.fromPassphrase(passphrase));const senderNonce = Utils.BigNumber.make(senderWallet.body.data.nonce).plus(1);// Step 2: Create the transactionconst transaction = new Builders.GuardianGroupPermissionsBuilder().GuardianGroupPermissions({name: "Test Guardian Permission Group",allow: [{ transactionType: 1, transactionTypeGroup: 1 }],priority: 1,active: true,default: false,}).nonce(senderNonce.toFixed()).sign(passphrase);// Step 3: Broadcast the transactionconst broadcastResponse = await client.api("transactions").create({ transactions: [transaction.build().toJson()] });// Step 4: Log the responseconsole.log(JSON.stringify(broadcastResponse.body.data, null, 4));};