Tropykus JS
Tropykus.js Library
A JavaScript SDK for Ethereum and the Tropykus Protocol. Wraps around Ethers.js. Works in the web browser and Node.js.
This SDK is in open beta, and is constantly under development. USE AT YOUR OWN RISK.
Install / Import
Node.js / ReactJS / VueJS
npm install @tropykus/tropykus-jsconst Tropykus = require("@tropykus/tropykus-js");
// or, when using ES6
import Tropykus from "@tropykus/tropykus-js";Web Browser
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/@tropykus/tropykus-js@latest/dist/browser/tropykus.min.js"
></script>
<script type="text/javascript">
window.Tropykus; // or `Tropykus`
</script>Instance Creation
This SDK can be used both on a browser as well as on a NodeJS application. If you are accessing with an injected provider such as Metamask, ensure that you are connected the the Rootstock Mainnet (or Rootstock Testnet) network
Instance Creation example using React + Wagmi 2.x.x
In this example we are creating an instance of the library in a NextJS application using RainbowKit v2.x.x. This code should serve as an example on how to use the library in a browser environment
Tropykus Protocol
Constants and Contract Addresses
Names of contracts, their addresses, ABIs, token decimals, and more can be found in /src/constants.ts. Addresses, for all networks, can be easily fetched using the getAddress function, combined with contract name constants.
Protocol actions: Supply, Borrow, Repay and Redeem
The SDK provides some simple methods to interact with the protocol.
Important: It is critical to set the gasLimit option on each transaction to ensure the exeuction of the method
The accepted assets to interact with the protocol are: RBTC, DOC and BPRO
API
Get User Balance
The Tropykus API was integrated in the product in order to easily fetch the data and perform calculations on a user balance. The main method is getUserBalance
In order to fetch to balance of a user simply call:
Response Schema
Get Markets
In order to fetch the markets information call getMarkets()
Response Schema
IMPORTANT: In order to access the API, the URL has to be whitelisted. Please contact the Tropykus team at contact@tropykus.com to whitelist your URL.
Transaction Options
Each method that interacts with the blockchain accepts a final optional parameter for overrides, much like Ethers.js overrides.
Ethereum Read & Write
This SDK also includes some methods to read and write on the blockchain directly using JSON RPC.
Read
Write
Mantissas
Parameters of number values can be plain numbers or their scaled up mantissa values. There is a transaction option boolean to tell the SDK what the developer is passing.
Test
Tests are available in ./test/*.test.js. The tests are configured in ./test/index.js. Methods are tested using a forked chain using ganache-core. A JSON RPC provider URL needs to be configured as an environment variable before running the tests (MAINNET_PROVIDER_URL). Archive state must be available to run the tests. For free archive node access, get a provider URL from Alchemy.
Build for Node.js & Web Browser
Web Browser Build
Node.js Build
Last updated