JavaScript SDK
Last updated
Was this helpful?
Last updated
Was this helpful?
The SDK provides a way to programmatically interact with 8Pay's smart contracts.
It allows you to manage the subscriptions to your plans (e.g. trigger billings or terminate them).
This is a module available through the .
Before installing, .
Installation is done using the command:
To see all package details on the npm registry, click .
This module uses under the hood, which is the most popular library used to interact with the Web 3.0
.
To keep things familiar with web3
, it follows the same strucure when sending transactions but adds additional functionalities.
To get started, import the module and provide it with an instance of web3
:
There are two ways to sign a transaction before broadcasting it to the blockchain:
Using an unlocked account (e.g. when using Metamask)
With privateKey
The gas consumed by a transaction can be estimated using the estimateGas
function which takes and options
object and returns the amount of gas as number:
The send
method accepts the same options available in web3
like gas
, gasPrice
, nonce
and so on.
The following events are emitted when sending a transaction: transactionHash
, receipt
, confirmation
and error
.
Here is the list of all the available methods for each billing model.
Bills subscriptions of a plan.
Parameters:
planId - id of the plan
subscriptionIds - array of subscription ids
Forcefully cancels subscriptions of a plan.
The sender account must be the plan's admin or an operational account with terminate permission.
Parameters:
planId - id of the plan
subscriptionIds - array of subscription ids
Bills subscriptions of a plan.
The sender account must be the plan's admin or an operational account with bill permission.
Parameters:
planId - id of the plan
subscriptionIds - array of subscription ids
amounts - array of amounts to charge for each subscription
Forcefully cancels subscriptions of a plan.
The sender account must be the plan's admin or an operational account with terminate permission.
Parameters:
planId - id of the plan
subscriptionIds - array of subscription on-chain ids
Bills subscriptions of a plan.
The sender account must be the plan's admin or an operational account with bill permission.
Parameters:
planId - id of the plan
subscriptionIds - array of subscription ids
amounts - array of amounts to charge for each subscription
Forcefully cancels subscriptions of a plan.
The sender account must be the plan's admin or an operational account with terminate permission.
Parameters:
planId - id of the plan
subscriptionIds - array of subscription ids
The accounts utility can be used to obtain an account object from a private key or a mnemonic. The account object has two properties: address
and privateKey
.
To help in parsing amount from and to ethereum decimals, you can use addDecimals
and parseDecimals
methods.