@fileverse/heartbit-core
Advanced tools
Comparing version 0.0.2 to 0.0.21
@@ -5,3 +5,3 @@ export const PUBLIC_RPC_URL_MAP = { | ||
}; | ||
export const HEART_MINTER_CONFIG = { | ||
export const HEART_BIT_CONFIG = { | ||
"0xaa36a7": { | ||
@@ -12,3 +12,2 @@ chainId: 11155111, | ||
publicRPCUrl: PUBLIC_RPC_URL_MAP.sepolia, | ||
apiKey: "hello", | ||
}, | ||
@@ -20,3 +19,2 @@ "0x2105": { | ||
publicRPCUrl: PUBLIC_RPC_URL_MAP.base, | ||
apiKey: "hello", | ||
}, | ||
@@ -23,0 +21,0 @@ }; |
@@ -12,4 +12,4 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
}; | ||
var _HeartBitCore_backendApi, _HeartBitCore_contract, _HeartBitCore_rpcProvider, _HeartBitCore_apiKey; | ||
import { HEART_MINTER_CONFIG } from "./constants"; | ||
var _HeartBitCore_backendApi, _HeartBitCore_contract, _HeartBitCore_rpcProvider; | ||
import { HEART_BIT_CONFIG } from "./constants"; | ||
import { JsonRpcProvider as JRPCProvider, } from "ethers"; | ||
@@ -28,3 +28,2 @@ import { getMinterContract, getHashedString } from "./utils"; | ||
_HeartBitCore_rpcProvider.set(this, void 0); | ||
_HeartBitCore_apiKey.set(this, void 0); | ||
const { chain, rpcUrl } = opts; | ||
@@ -34,13 +33,11 @@ if (!chain) | ||
this.chain = chain; | ||
__classPrivateFieldSet(this, _HeartBitCore_backendApi, HEART_MINTER_CONFIG[chain].backendApi, "f"); | ||
__classPrivateFieldSet(this, _HeartBitCore_rpcProvider, new JRPCProvider(rpcUrl || HEART_MINTER_CONFIG[chain].publicRPCUrl), "f"); | ||
__classPrivateFieldSet(this, _HeartBitCore_backendApi, HEART_BIT_CONFIG[chain].backendApi, "f"); | ||
__classPrivateFieldSet(this, _HeartBitCore_rpcProvider, new JRPCProvider(rpcUrl || HEART_BIT_CONFIG[chain].publicRPCUrl), "f"); | ||
__classPrivateFieldSet(this, _HeartBitCore_contract, getMinterContract(chain, __classPrivateFieldGet(this, _HeartBitCore_rpcProvider, "f")), "f"); | ||
__classPrivateFieldSet(this, _HeartBitCore_apiKey, HEART_MINTER_CONFIG[chain].apiKey, "f"); | ||
} | ||
async mintHeartBit(opts) { | ||
await fetch(__classPrivateFieldGet(this, _HeartBitCore_backendApi, "f"), { | ||
const response = await fetch(__classPrivateFieldGet(this, _HeartBitCore_backendApi, "f"), { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"x-api-key": __classPrivateFieldGet(this, _HeartBitCore_apiKey, "f"), | ||
}, | ||
@@ -51,2 +48,4 @@ body: JSON.stringify({ | ||
}); | ||
const data = await response.json(); | ||
return data; | ||
} | ||
@@ -56,3 +55,4 @@ async getTotalHeartBitCountByHash(opts) { | ||
const tokenId = await this.getHeartbitHashTokenMap(hash); | ||
return await __classPrivateFieldGet(this, _HeartBitCore_contract, "f").totalSupply?.(tokenId); | ||
const balance = await __classPrivateFieldGet(this, _HeartBitCore_contract, "f").totalSupply?.(tokenId); | ||
return parseInt(balance); | ||
} | ||
@@ -70,4 +70,4 @@ async getHeartbitHashTokenMap(url) { | ||
} | ||
_HeartBitCore_backendApi = new WeakMap(), _HeartBitCore_contract = new WeakMap(), _HeartBitCore_rpcProvider = new WeakMap(), _HeartBitCore_apiKey = new WeakMap(); | ||
_HeartBitCore_backendApi = new WeakMap(), _HeartBitCore_contract = new WeakMap(), _HeartBitCore_rpcProvider = new WeakMap(); | ||
export { getHashedString, }; | ||
//# sourceMappingURL=index.js.map |
import { keccak256, toUtf8Bytes, Contract } from "ethers"; | ||
import { CONTRACT_ABI, HEART_MINTER_CONFIG } from "../constants"; | ||
import { CONTRACT_ABI, HEART_BIT_CONFIG } from "../constants"; | ||
export const getHashedString = (str) => keccak256(toUtf8Bytes(str)); | ||
export const getMinterContract = (chain, rpcProvider) => { | ||
const minterConfig = HEART_MINTER_CONFIG[chain]; | ||
const minterConfig = HEART_BIT_CONFIG[chain]; | ||
const { contractAddress } = minterConfig; | ||
@@ -7,0 +7,0 @@ return new Contract(contractAddress, CONTRACT_ABI, rpcProvider); |
@@ -6,3 +6,3 @@ import type { HeartBitConfig } from "../types/index.js"; | ||
}; | ||
export declare const HEART_MINTER_CONFIG: HeartBitConfig; | ||
export declare const HEART_BIT_CONFIG: HeartBitConfig; | ||
export declare const CONTRACT_ABI: { | ||
@@ -9,0 +9,0 @@ inputs: { |
@@ -7,4 +7,4 @@ import type { TotalHeartBitCountArgs, HeartBitCoreOptions, MintHeartBitArgs, SupportedChain, HeartBitCountByUserArgs } from "./types"; | ||
constructor(opts: HeartBitCoreOptions); | ||
mintHeartBit(opts: MintHeartBitArgs): Promise<void>; | ||
getTotalHeartBitCountByHash(opts: TotalHeartBitCountArgs): Promise<any>; | ||
mintHeartBit(opts: MintHeartBitArgs): Promise<any>; | ||
getTotalHeartBitCountByHash(opts: TotalHeartBitCountArgs): Promise<number>; | ||
getHeartbitHashTokenMap(url: string): Promise<any>; | ||
@@ -11,0 +11,0 @@ getHeartBitByUser(opts: HeartBitCountByUserArgs): Promise<number>; |
@@ -5,5 +5,4 @@ export type SupportedChain = "0xaa36a7" | "0x2105"; | ||
backendApi: string; | ||
publicRPCUrl: string; | ||
contractAddress: string; | ||
publicRPCUrl: string; | ||
apiKey: string; | ||
}; | ||
@@ -20,9 +19,9 @@ export type HeartBitConfig = { | ||
} | ||
export type TotalHeartBitCountArgs = { | ||
export interface TotalHeartBitCountArgs { | ||
hash: string; | ||
}; | ||
export type HeartBitCountByUserArgs = { | ||
} | ||
export interface HeartBitCountByUserArgs { | ||
hash: string; | ||
address: string; | ||
}; | ||
} | ||
export interface HeartBitCoreOptions { | ||
@@ -29,0 +28,0 @@ chain: SupportedChain; |
{ | ||
"name": "@fileverse/heartbit-core", | ||
"version": "0.0.2", | ||
"version": "0.0.21", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
100
README.md
@@ -1,9 +0,17 @@ | ||
# @fileverse/heartbit-core | ||
# HeartBit Core | ||
## Introduction | ||
This is the core of the HeartBit functionality. It exposes the APIs that are crucial for implementing HeartBit functionalities. | ||
## Getting Started | ||
### Installation | ||
``` | ||
You can install the package using either `npm` or `yarn`: | ||
```javascript | ||
npm install --save @fileverse/heartbit-core | ||
//or | ||
// or | ||
@@ -13,69 +21,53 @@ yarn add @fileverse/heartbit-core | ||
## HeartBitCore | ||
### Import and Use the Package | ||
### Interface | ||
```javascript | ||
type SupportedChain = "0xaa36a7" | "0x2105"; | ||
import { HeartBitCore } from "@fileverse/heartbit-core"; | ||
``` | ||
interface HeartBitCoreOptions { | ||
chain: SupportedChain; | ||
rpcUrl?: string; | ||
} | ||
### Configure the Package | ||
interface TotalHeartBitCountArgs { | ||
hash: string; // keccak256 hash of a string | ||
} | ||
The SDK utilizes `coreOption` to configure the network for user interactions. | ||
interface HeartBitCountByUserArgs { | ||
hash: string; // keccak256 hash of a string | ||
address: string; // ethereum wallet address | ||
} | ||
interface MintHeartBitArgs { | ||
message: string; | ||
signature: string; | ||
startTime: number; // in seconds | ||
endTime: number; // in seconds | ||
hash: string; // keccak256 hash of a string | ||
} | ||
```javascript | ||
const coreSDK = new HeartBitCore({ | ||
chain: "0xaa36a7", | ||
}); | ||
``` | ||
### Usage | ||
### Example Usage | ||
This minimal example demonstrates how to use `HeartBitCore` for minting and querying data. | ||
```javascript | ||
import { HeartBitCore } from "@fileverse/heartbit-core"; | ||
const coreSDK = new HeartBitCore({ | ||
chain: "0xaa36a7", | ||
}); | ||
async function main() { | ||
const message = "Hello World!"; | ||
const signature = "0x...signed message"; | ||
const startTime = 1706898250; | ||
const endTime = 1706898251; | ||
const hash = "Hello World"; // keccak256 hash of a string | ||
const message = "Hello World!"; | ||
const signature = "0x...signed message"; | ||
const startTime = 1706898250; | ||
const endTime = 1706898251; | ||
const hash = "Hello World"; // keccak256 hash of a string | ||
// Mint HeartBit | ||
// Mint HeartBit | ||
await coreSDK.mintHeartBit({ | ||
message, | ||
signature, | ||
startTime, | ||
endTime, | ||
hash, | ||
}); | ||
await coreSDK.mintHeartBit({ | ||
message, | ||
signature, | ||
startTime, | ||
endTime, | ||
hash, | ||
}); | ||
// Get TotalSupply for a hash | ||
// Get TotalSupply for a hash | ||
const totalSupply = await coreSDK.getTotalHeartBitCountByHash({ hash }); | ||
const totalSupply = await coreSDK.getTotalHeartBitCountByHash({ hash }); | ||
// Get Total Mints By User | ||
const address = "0x...ethaddress"; | ||
const mintsByUser = await coreSDK.getHeartBitByUser({ | ||
hash, | ||
address, | ||
}); | ||
// Get Total Mints By User | ||
const address = "0x...ethaddress"; | ||
const mintsByUser = await coreSDK.getHeartBitByUser({ | ||
hash, | ||
address, | ||
}); | ||
} | ||
``` | ||
[Here](https://codesandbox.io/p/devbox/heartbit-core-sdk-example-37h7hw) is a link to a working example using `HeartBitCore`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68599
269
73