hapi-core

Crates.iohapi-core
lib.rshapi-core
version0.2.0
sourcesrc
created_at2022-05-17 14:20:07.531284
updated_at2023-01-17 11:54:17.476299
descriptionCore contract of HAPI Protocol
homepagehttps://hapi.one
repositoryhttps://github.com/HAPIprotocol/hapi-core
max_upload_size
id588342
size72,529
HAPI Dev (hapione)

documentation

https://hapi-one.gitbook.io/

README

HAPI Core

HAPI Core contract built on Anchor for Solana. If you want to know more about HAPI Protocol, please visit the official site and our gitbook. If you want to propose any changes to this smart contract, please visit our governance forum. Suggestions for the client library enhancements are welcome.

Dependencies

To install everything you need to work with this project, you'll need to install dependencies as described in Anchor documentation.

Program

The source code of hapi-core program is in ./programs/hapi-core.

Build

To build the hapi-core program, you need to execute this command:

anchor build

You'll get the following output:

  • program binaries at ./target/deploy/hapi_core.so
  • IDL file at ./target/idl/hapi_core.json
  • Typescript typings at ./target/types/hapi_core.ts

Test

To test the program, you'll have to run this command:

anchor test

This command starts a local validator, sets up the program on chain and runs a suite of Jest tests against it.

Deploy

To deploy the program, run this command:

anchor deploy \
    --provider.cluster https://api.mainnet-beta.solana.com \
    --provider.wallet ~/.config/solana/id.json

Where provider.cluster is the target node API and provider.wallet is the path to keypair you want to use to deploy the program.

Javascript client

The Javascript/Typescript client for this program is an NPM package that can be found here: @hapi.one/core-cli.

It's published by this command:

npm publish

Please view the test suite (./tests/hapi-core/**.spec.ts) to see how can this client be used in NodeJS context.

Basic usage example in browser

import { Connection, PublicKey } from "@solana/web3.js";
import { Provider } from "@project-serum/anchor";
import { initHapiCore } from "@hapi.one/core-cli";

// Setup web3 Connection
const connection = new Connection("https://api.mainnet-beta.solana.com");

// Use Phantom wallet provider
const wallet = window.solana;

// Setup Anchor provider
const provider = new Provider(connection, wallet as any);

// hapi-core program ID is a well-known public key
const HAPI_PROGRAM_ID = new PublicKey(
  "hapiAwBQLYRXrjGn6FLCgC8FpQd2yWbKMqS6AYZ48g6"
);

// Setup the client
const hapiCore = initHapiCore(HAPI_PROGRAM_ID, provider);

// HAPI community account is a well-known public key
const communityAccount = new PublicKey(
  "31gQ11Qsd7dPcnkdCJ2ZGnY2ijRXsvFCPWagpcFxYwem"
);

// Use client to fetch community account data
const communityData = await hapiCore.account.community.fetch(communityAccount);
console.log(communityData);

// Find a PDA for a particular network
const [networkAccount] = await program.pda.findNetworkAddress(
  communityAccount,
  "solana"
);

// Encode address buffer
const addressEncoded = hapiCore.util.encodeAddress(
  "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
  "Solana"
);

// Find a PDA for an address, which we want to check
const [addressAccount] = await program.pda.findAddressAddress(
  networkAccount,
  addressEncoded
);

// Fetch address risk scoring data
const addressData = await hapiCore.account.address.fetch(addressAccount);
console.log(addressData);
Commit count: 528

cargo fmt