HAPI Solana client
This library provides three types of clients of HAPI smart contract on Solana:
- ReaderClient: a read-only client to fetch data from the smart contract
- AuthorityClient: a client to access community management smart contract methods
- ReporterClient: a client to access reporting methods of the smart contract
Usage examples
ReaderClient
import { ReaderClient, u64 } from '@hapi.one/solana-client';
const reader = new ReaderClient({ endpoint: "https://api.mainnet-beta.solana.com" });
const communityInfo = await reader.getCommunity("hapi.one");
const networkInfo1 = await reader.getNetwork("solana", "hapi.one");
reader.switchCommunity("hapi.one");
const reader2 = new ReaderClient({ endpoint: "https://api.mainnet-beta.solana.com", communityName: "hapi.one" });
const networkInfo2 = await reader.getNetwork("bitcoin");
const reporterAccount = new PublicKey("GNNtJU2WCuk1q8uLW6aXHwFcZvrgbzRrtwuQqYkaCKSY");
const reporterInfo = await reader.getReporter(reporterAccount);
const caseInfo = await reader.getCase(new u64(420));
const addressInfo1 = await reader.getAddress("9Y9eHFk6tyadkz3e4zpYxvAuTumkLHSXV2tZQhxjb6xf", "solana-mainnet");
const buffer = Buffer.alloc(32);
const pizzaTransactionAddress = Buffer.from("0046af3fb481837fadbb421727f9959c2d32a3682971c823e7", "hex");
buffer.set(pizzaTransactionAddress);
const addressInfo2 = await reader.getAddress(buffer, "bitcoin-mainnet");
ReporterClient
ReporterClient
extends ReaderClient
, so all the getter methods are the same.
import { Keypair, PublicKey, Connection } from '@solana/web3.js';
import { ReporterClient, u64, Category } from '@hapi.one/solana-client';
const payer = Keypair.generate();
const reporter = new ReporterClient({ endpoint: "https://api.mainnet-beta.solana.com", payer });
reporter.switchCommunity("hapi.one");
const resultCase = await reporter.createCase("Exchange hack 2021-10-08", [Category.Theft]);
const resultAddress = await reporter.createAddress(
"solana",
new PublicKey("vwiVuBCPvFW5GJTM9Z2CbAuard5xP4Cyjn8gFjnUxy4"),
resultCase.meta.caseId,
Category.Theft,
5,
);
const payer2 = new PublicKey("9Y9eHFk6tyadkz3e4zpYxvAuTumkLHSXV2tZQhxjb6xf");
const reporter2 = new ReporterClient({ endpoint: "https://api.mainnet-beta.solana.com", payer: payer2 });
const transaction = await reporter2.createCaseTransaction("Rug pull", [Category.Scam]);
const conn = new Connection("https://api.mainnet-beta.solana.com");
await conn.sendRawTransaction(transaction.serialize());