
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
@spheron/desub-js
Advanced tools
Typescript library for working with the decentralised subscription contracts in Spheron
🧰 Desub Js is the ultimate solution for working with the Decentralized Subscription Contracts. Powered by Spheron.
Spheron is a marketplace to access all your web3 infrasructures.
A simple guide for using the desub package to interacts with your contract. The smart contract can be found here. If you make any significant change to the contracts, then you'll have to make some some changes to the package and copy the ABIs to the constants/subscription.ts file. Contracts can be deployed on any EVM chain with support for solidity. If you are adopting the spheron contract without significant change, you can proceed to follow this quick guide.
Note: ethers is a peer dependency of this library, so it is mandatory to install ethers separately along with the @spheron/desub-js
library.
Using NPM
npm install @spheron/desub-js ethers
Using Yarn
yarn add @spheron/desub-js ethers
To use the desub-js functions, you will need to follow the steps outlined below:
import * as paymentSmartContract from "@spheron/desub-js";
import { Wallet } from "@ethersproject/wallet";
subContractData
: an object with paymentContractAddress
, dataContractAddress
, tokenAddress
, and tokenPrecision
properties.tokenAddress
: the address of the token contract.tokenPrecision
: the number of decimals the token has.walletAddress
: the address of the wallet to check the balance for.const httpProvider = "<insert provider URL>";
This URL should point to a node that can communicate with the EVM chain.
const signer = Wallet.fromMnemonic("<Inser wallet mnemonic>").connect(httpProvider);
This step requires a mnemonic phrase that corresponds to the wallet being used.
const vendor = new paymentSmartContract.Vendor(httpProvider, signer);
This class is used to interact with the payment contract.
const subscription = new paymentSmartContract.Subscription(vendor);
This class is used to interact with the data contract.
subscriptionAt
method to set the subscription data:await subscription.subscriptionAt(paymentContractAddress, dataContractAddress, tokenAddress, tokenPrecision);
getUserTokenBalance
method on the subscription
object, passing in the walletAddress
parameter. This method retrieves the available balance of the user's token in the payment smart contract. The available balance is then returned by the function.const availableBalance = await subscription.getUserTokenBalance(walletAddress);
Following these steps will allow you to use the getUserTokenBalance
function in desub-js.
If you would like to build the Desub.JS package locally, follow the steps below. Please note that our current latest stable branch is Master. After cloning, make sure you are on the Master branch.
Clone the Desub.JS code into your local repository by using git clone https://github.com/spheronFdn/desub-js.git
.
Install packages using either yarn or npm from the root folder. You can use yarn
or npm install
.
Run yarn build
or npm run build
.
If you would like to test the Desub.JS package, follow the steps below. Please note that you need to have all the necessary values in the .env
file before running tests. You can ping us on Discord, and we will be happy to share our .env
file with you.
git clone https://github.com/spheronFdn/desub-js.git
.yarn
or npm install
..env
file before running tests.yarn test
or npm test
.A sample .env
file would look like:
COINMARKETCAP_KEY="COINMARKET_CAP_API_KEY"
BICONOMY_KEY="BICONOMY_API_KEY"
MNEMONIC_TEST="MNEMONIC_FOR_ACCOUNT"
RPC_ENDPOINT="JSON_RPC_ENDPOINT_FOR_ETHEREUM_NETWORK"
Note: you can ping us on discord and we will be happy to share our .env file with you
We encourage you to read the contribution guidelines to learn about our development process and how to propose bug fixes and improvements before submitting a pull request.
The Spheron community extends beyond issues and pull requests! You can support Spheron in many other ways as well.
For help, discussions or any other queries: Join us on Discord
FAQs
Typescript library for working with the decentralised subscription contracts in Spheron
The npm package @spheron/desub-js receives a total of 38 weekly downloads. As such, @spheron/desub-js popularity was classified as not popular.
We found that @spheron/desub-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.