0.2.6 • Published 2 years ago

pablock-sdk v0.2.6

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
2 years ago

Pablock SDK

Pablock SDK is a set of tool to help developer interact with Pablock API.

Written in Typescript and tested with Jest

Installation

From source code:

npm install git+https://github.com/bcode-tech/pablock-sdk.git

From npm:

npm install --save pablock-sdk

Usage

First you need to call the constructor, if you want to generate a new Wallet every time you can implemented like this:

const { PablockSDK } = require("pablock-sdk")

(async () => {

    const sdk = new PablockSDK({
        apiKey: <your-api-key>,
        config: { env: <environment>, debugMode: true },
    });

    await sdk.init()
})()

Otherwise if you already have a private key that you want to use you can use:

const { PablockSDK } = require("pablock-sdk")

(async () => {

    const sdk = new PablockSDK({
        apiKey: <your-api-key>,
        privateKey: <private-key>,
        config: { env: <environment>, debugMode: true },
    });

    await sdk.init()
})()

It's possible to change private key later:

const { PablockSDK } = require("pablock-sdk")

(async () => {

    const sdk = new PablockSDK({
        apiKey: <your-api-key>,
        privateKey: <private-key>,
        config: { env: <environment>, debugMode: true },
    });

    await sdk.init()

    sdk.setPrivateKey("private_key")
})()

Constructor config object parameters:

ParamDefault valueOptions
envMUMBAIMUMBAI, POLYGON
debugModefalsetrue, false

Test

For running test you need to create privateKeys.json, with an array of at least 3 privateKeys to submit to test script.

Functions

init()

Initilize user wallet and configure


setPrivateKey()

Set private key after creation, to enable auth logic

Params

ParamDefault value
privateKeyWallet private key

setMnemonicPhrase()

Set mnemonic phrase after creation, to enable auth logic

Params

ParamDefault value
mnemonicWallet mnemonic phrase

resetWallet()

Reset wallet to null and delete private key


regenerateWallet()

Generate new wallet after creation or after deleting previous one


getAuthToken()

Returns authToken received from Pablock API to authenticate call, it depends on API Key used.


getAPIKey()

Returns apiKey used in contructor, just for reference.


getWalletAddress(address)

Returns address for generated wallet.

getPablockTokenBalance(address)

Return Pablock Token (PTK) balance of current wallet or the specified address.

Params

ParamDefault value
addressuser address

getMaticBalance()

Return MATIC balance of the current wallet or the specidfied address.

Params

ParamDefault value
addressuser address

requestToken(amount, contractAddress)

Function for request minting of CustomERC20 token.

ParamDescriptioon
amountToken quantity to mint
contractAddressAddress of CustomERC20 token contract

prepareTransaction(contractObj, functionName, params)

Prepare transaction that need to be executed through meta transaction.

ParamDefault valueDescription
contractObjArray with Pablock NFT ContractArray of interested contract addresses
functionNameCurrent user addressWallet address of NFT owner
paramsArrayArray of original prams for contract function

Example:

const tx = await sdk.prepareTransaction(
  {
    address: config[`TEST_META_TX_${env}`],
    abi: testMetaTxAbi,
    name: "TestMetaTransaction",
    version: "0.0.1",
  },
  "increment",
  []
));

executeTransaction(tx, optionals)

Prepare transaction that need to be executed through meta transaction.

ParamDescription
txArray of interested contract addresses
optionalsObject with webhookUrl, secret and metadata

Example:

type MetaTransaction = {
  contractAddress: string;
  userAddress: string;
  functionSignature: string;
  r: string;
  s: string;
  v: any;
};

type Optionals = {
  webhookUrl: string | null;
  metadata: { [key: string]: any } | null;
  secret: string | null;
};

async executeTransaction(tx: MetaTransaction, optionals: Optionals | null)

executeAsyncTransaction(tx, optionals)

Prepare transaction that need to be executed through meta transaction in async mode. API return a requestId needed to refetch transaction status later.

ParamDescription
txArray of interested contract addresses
optionalsObject with webhookUrl, secret and metadata

Example:

type MetaTransaction = {
  contractAddress: string;
  userAddress: string;
  functionSignature: string;
  r: string;
  s: string;
  v: any;
};

type Optionals = {
  webhookUrl: string | null;
  metadata: { [key: string]: any } | null;
  secret: string | null;
};

async executeAsyncTransaction(tx: MetaTransaction, optionals: Optionals | null)

notarizeHash(hash, optionals)

Request meta transaction notarization, return notarization receipt.

ParamDescription
hashHash of document to notarize
optionalsObject with webhookUrl, secret and metadata

Example:

type Optionals = {
  webhookUrl: string | null;
  metadata: { [key: string]: any } | null;
  secret: string | null;
};

async notarizeHash(hash: string, optionals: Optionals | null)

checkBundleNotarization(requestId, returnParams)

Return bundled notarization data.

ParamDescription
requestIdString id returned from notarizeHash call
returnParamsArray of params

Example:

type ReturnParam = "leaves" | "merkleRoot" | "merkleProof" | "inclusion";

async checkBundledNotarization(requestId: string, returnParams: ReturnParam[])

getMetaTxStatus(requestId)

Return meta transaction status, receipt, ethereum anchor tx.

ParamDescription
requestIdString id returned from executeAsyncTransaction call

Example:

async getMetaTxRequest(requestId: string)

mintPablockNFT(amount, uri, contractAddress, webhookUrl)

Function for request mint of an NFT.

ParamDefault valueDescription
amountnoneAmount of NFT to mint
urinoneURI of NFT resources
contractAddresPablock NFT ContractAddress of CustomNFT contract
webhookUrlnullURL of webhook endpoint on which receive a response

sendPablockNFT(to, tokenId, deadline, contractAddress)

Function for send NFT. It has a built-in permit request to allow Pablock to transfer NFT for user wallet.

ParamDefault valueDescription
tononeReceiver of NFT
tokenIdnoneTokenID of NFT to transfer
contractAddressPablock NFT ContractAddress of CustomNFT contract

getOwnedNFT(contractAddresses, ownerAddress)

Function that returns all NFT for the passes contract addresses for the given owner address.

ParamDefault valueDescription
contractAddressesArray with Pablock NFT ContractArray of interested contract addresses
ownerAddressCurrent user addressWallet address of NFT owner

checkJWTValidity()

Function that check if fetched JWT is still valid


getAPIVersion()

Returns Pablock API service version, just to check if the service is available

Made with ❤️ by BCode

0.2.6

2 years ago

0.2.5

2 years ago

0.2.3

2 years ago

0.2.4

2 years ago

0.2.2

2 years ago

0.2.0

2 years ago