@lastrust/bunzz-sdk v1.1.10
Bunzz SDK
The Bunzz SDK implements a client-side library for interaction with smart contracts used by Bunzz services. This SDK distributed via:
Installing:
yarn add bunzz-sdk
npm i bunzz-sdk --save
Getting started:
import { bunzz, BunzzContract, BunzzTransaction } from 'bunzz-sdk';
export const handler = await bunzz.initializeHandler({
apiKey,
dappId
});
export const ContractExample: BunzzContract = handler.getContract('ContractExample');
export const doSomething = async (id: number, amount: number): Promise<void> => {
try {
const signerAddress = await handler.getAddress();
const tx: BunzzTransaction = ContractExample.mint(signerAddress, id, amount);
const res = tx.wait();
console.log('Token successfully minted! Congratulation 🎉')
} catch (err) {
console.error(err);
}
}
Documentation:
Bunzz:
initializeHandler({apiKey: string, appId: number, contractId: number}): Handler
Static method for initialize Handler. The initialization process requires values of apiKey
, dappId
, which you can get from your console in the bunzz dashboard.
import { bunzz } from 'bunzz-sdk';
export const handler = await bunzz.initializeHandler({
apiKey: string,
dappId: string
});
Handler:
getInstance(configs: ContractConfig[]): Handler
Returns instance of a handler, which has access to all methods for working with ethereum smart contracts.
import { handler } from 'bunzz-sdk';
const handlerInstance = handler.getInstance();
getProvider(): EtherProvider
Returns current ethereum provider.
const provider = handler.getProvider();
getCurrentAddress(): string
Returns the current address of the provider.
const address = handler.getCurrentAddress();
convertToBlockNumber({date: string, timezone?: string, blocksPerMinute?: number}): {timestamp: number, block: number}
Converts timestamp to block number. Could count past, current, and future blocks in ethereum network.
const arg = {date: '2020-05-01T03:00', timezone: 'UTC'}
const {block, timestamp} = handler.convertToBlockNumber(arg);
Handler.getContract(name: string): BunzzContract
Returns BunzzContract, which has access to getting values and calling methods.
const myContract = handler.getContract('ContractName');
BunzzContract:
BunzzContract.MethodName: BunzzTransaction
The method name is variable name functions. Functions, which requires gas, called from BunzzContract returns BunzzTransaction object.
const tx: BunzzTransaction = ContractExample.mint(signerAddress, id, amount);
const res = tx.wait();
For the view
and pure
methods returns ViewResponse
. ViewResponse
has a normalize
method for converting Ether BigNumber
response to strings in hex.
const res = ContractExample.getBalance(walletAddress);
const normalizedRes = res.normalize();
BunzzTransaction:
Transaction which returned from a calling of payable
or nonpayble
methods.
interface BunzzTransaction {
hash: string;
wait(): TransactionResponse // waiting until a transaction has been minted
}
3 years ago