@setl/setl-drex-sdk
v1.0.4
Published
An SDK for SETL Drex
Downloads
3
Readme
SETL DREX SDK
SDK for triggering actions on SETL Drex
Prerequisites
This project requires NodeJS (developed on v18) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.
$ npm -v && node -v
6.4.1
v8.16.0
Table of contents
Getting Started
Set up a new nodejs project in your development environment and install the library as follows
$ npm install @setl/setl-drex-sdk
Usage
const drex = require("setl-drex-sdk");
const DREX = new drex("drex.setllabs.io", "usernameHere", "passwordHere");
/* ------------------------------------------------------------------------
//
// User Tests
//
-------------------------------------------------------------------------- */
console.log("[user.users]");
res = await DREX.user.users();
console.log(res);
console.log("------------------");
console.log("[user.adduser]");
res = await DREX.user.adduser({ user: "bank3", password: "passwordHere" });
console.log(res);
console.log("------------------");
console.log("[user.addaccount]");
res = await DREX.user.addaccount({ name: "random" });
console.log(res);
console.log("------------------");
console.log("[user.wallet]");
res = await DREX.user.wallet();
console.log(res);
console.log("------------------");
console.log("[user.importaccount]");
res = await DREX.user.importaccount({ name: "random", privateKey: "" });
console.log(res);
console.log("------------------");
console.log("[user.addblockchain]");
res = await DREX.user.addblockchain({
name: "name",
url: "url",
port: "8545",
network_id: "1337",
AddressDiscovery: "0xb88430191c51f6f8898cd9d73b5e41cf72489175",
RealDigitalDefaultAccount: "0x9f39656bc0810f8ffa0a9191199e1fda8b336edf",
KeyDictionary: "0xbdefc637bfbbee4472d8e6d4ebc35bc489699b65",
RealDigital: "0xba13c47d373a81ec4e8fc472251b2ddedd220548",
RealTokenizado: "0x474b7079eab8872476aba0404d4fca86274306a4",
RealToken1: "0xd9ee424b9a84d2c5c11840a38cec01f79127ec5b",
RealToken2: "0x474b7079eab8872476aba0404d4fca86274306a4",
STR: "0x94319b769f89a6cc64694cc20d1b8bf3bb7fa3a3",
SwapOneStep: "0x446a54fa07ef8581a29577157152466228a720c5",
SwapTwoSteps: "0x9eb873633d816e8f00648ac6811f4a794d88312b",
});
console.log(res);
console.log("------------------");
console.log("[user.getblockchains]");
res = await DREX.user.getblockchains();
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Deploy Tests
//
-------------------------------------------------------------------------- */
console.log("[deploy.createtokenizado]");
res = await DREX.deploy.createtokenizado({
contractName: "Bank1Token",
contractSymbol: "B1T",
participantName: "Bank1",
participantNumber: 44444444,
});
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Address Discovery Tests
//
-------------------------------------------------------------------------- */
console.log("[addressdiscovery.changeauthority]");
res = await DREX.addressdiscovery.changeauthority({
fromAddress: "0x1bFb4082eF7C3B2aea594f3D6F5893A6feAA62C6",
changeAddress: "0xd6Ab06b7270b4498a6E726Cda374Ed8F251824CB",
});
console.log(res);
console.log("------------------");
console.log("[addressdiscovery.hasrole]");
res = await DREX.addressdiscovery.hasrole({
address: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
console.log("[addressdiscovery.grantrole]");
res = await DREX.addressdiscovery.grantrole({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
console.log("[addressdiscovery.revokerole]");
res = await DREX.addressdiscovery.revokerole({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Digital Real Tests
//
-------------------------------------------------------------------------- */
console.log("[digitalreal.name]");
res = await DREX.digitalreal.name();
console.log(res);
console.log("------------------");
console.log("[digitalreal.admin]");
res = await DREX.digitalreal.admin();
console.log(res);
console.log("------------------");
console.log("[digitalreal.authority]");
res = await DREX.digitalreal.authority();
console.log(res);
console.log("------------------");
console.log("[digitalreal.symbol]");
res = await DREX.digitalreal.symbol();
console.log(res);
console.log("------------------");
console.log("[digitalreal.decimals]");
res = await DREX.digitalreal.decimals();
console.log(res);
console.log("------------------");
console.log("[digitalreal.totalSupply]");
res = await DREX.digitalreal.totalSupply();
console.log(res);
console.log("------------------");
console.log("[digitalreal.balanceof]");
res = await DREX.digitalreal.balanceof();
console.log(res);
console.log("------------------");
console.log("[digitalreal.balanceofall]");
res = await DREX.digitalreal.balanceofall();
console.log(res);
console.log("------------------");
console.log("[digitalreal.mint]");
res = await DREX.digitalreal.mint({
fromAddress: "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1",
toAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.burn]");
res = await DREX.digitalreal.burn({
fromAddress: "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1",
toAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.transfer]");
res = await DREX.digitalreal.transfer({
fromAddress: "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1",
toAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.verifyaccount]");
res = await DREX.digitalreal.verifyaccount({
address: "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1",
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.enableaccount]");
res = await DREX.digitalreal.enableaccount({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
addressToEnable: "0xd03ea8624C8C5987235048901fB614fDcA89b117",
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.disableaccount]");
res = await DREX.digitalreal.disableaccount({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
addressToDisable: "0xd03ea8624C8C5987235048901fB614fDcA89b117",
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.allowance]");
res = await DREX.digitalreal.allowance({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0xd03ea8624C8C5987235048901fB614fDcA89b117",
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.transferfrom]");
res = await DREX.digitalreal.transferfrom({
fromAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
transferFromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0xb2c3ac072F7Cf2D4de08fA37471e8bF4080e68Ea",
amount: 5,
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.increaseallowance]");
res = await DREX.digitalreal.increaseallowance({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.decreaseallowance]");
res = await DREX.digitalreal.decreaseallowance({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.frozenbalanceof]");
res = await DREX.digitalreal.frozenbalanceof();
console.log(res);
console.log("------------------");
console.log("[digitalreal.increasefrozenbalance]");
res = await DREX.digitalreal.increasefrozenbalance({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
freezeAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.decreasefrozenbalance]");
res = await DREX.digitalreal.decreasefrozenbalance({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
freezeAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.hasrole]");
res = await DREX.digitalreal.hasrole({
address: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.grantrole]");
res = await DREX.digitalreal.grantrole({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
console.log("[digitalreal.revokerole]");
res = await DREX.digitalreal.revokerole({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Real Tokenizado Tests
//
-------------------------------------------------------------------------- */
console.log("[realtokenizado.name]");
res = await DREX.realtokenizado.name({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.cnpj8]");
res = await DREX.realtokenizado.cnpj8({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.reserve]");
res = await DREX.realtokenizado.reserve({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.participant]");
res = await DREX.realtokenizado.participant({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.admin]");
res = await DREX.realtokenizado.admin({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.authority]");
res = await DREX.realtokenizado.authority({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.symbol]");
res = await DREX.realtokenizado.symbol({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.decimals]");
res = await DREX.realtokenizado.decimals({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.totalSupply]");
res = await DREX.realtokenizado.totalSupply({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.balanceof]");
res = await DREX.realtokenizado.balanceof({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.balanceofall]");
res = await DREX.realtokenizado.balanceofall({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.mint]");
res = await DREX.realtokenizado.mint({
contractName: "Bank1Token",
fromAddress: "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1",
toAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.burn]");
res = await DREX.realtokenizado.burn({
contractName: "Bank1Token",
fromAddress: "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1",
toAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.transfer]");
res = await DREX.realtokenizado.transfer({
contractName: "Bank1Token",
fromAddress: "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1",
toAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.verifyaccount]");
res = await DREX.realtokenizado.verifyaccount({
contractName: "Bank1Token",
address: "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.enableaccount]");
res = await DREX.realtokenizado.enableaccount({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0xd03ea8624C8C5987235048901fB614fDcA89b117",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.disableaccount]");
res = await DREX.realtokenizado.disableaccount({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0xd03ea8624C8C5987235048901fB614fDcA89b117",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.allowance]");
res = await DREX.realtokenizado.allowance({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0xd03ea8624C8C5987235048901fB614fDcA89b117",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.transferfrom]");
res = await DREX.realtokenizado.transferfrom({
contractName: "Bank1Token",
fromAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
transferFromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0xb2c3ac072F7Cf2D4de08fA37471e8bF4080e68Ea",
amount: 5,
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.increaseallowance]");
res = await DREX.realtokenizado.increaseallowance({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.decreaseallowance]");
res = await DREX.realtokenizado.decreaseallowance({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.frozenbalanceof]");
res = await DREX.realtokenizado.frozenbalanceof({
contractName: "Bank1Token",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.increasefrozenbalance]");
res = await DREX.realtokenizado.increasefrozenbalance({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.decreasefrozenbalance]");
res = await DREX.realtokenizado.decreasefrozenbalance({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
amount: 10,
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.updatereserve]");
res = await DREX.realtokenizado.updatereserve({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
reserveAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.hasrole]");
res = await DREX.realtokenizado.hasrole({
contractName: "Bank1Token",
address: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.grantrole]");
res = await DREX.realtokenizado.grantrole({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
console.log("[realtokenizado.revokerole]");
res = await DREX.realtokenizado.revokerole({
contractName: "Bank1Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Real Digital Default Account Tests
//
-------------------------------------------------------------------------- */
console.log("[realdigitaldefaultaccount.defaultaccount]");
res = await DREX.realdigitaldefaultaccount.defaultaccount({
cnpj8: 44444444,
});
console.log(res);
console.log("------------------");
console.log("[realdigitaldefaultaccount.adddefaultaccount]");
res = await DREX.realdigitaldefaultaccount.adddefaultaccount({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
cnpj8: 44444444,
account: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
});
console.log(res);
console.log("------------------");
console.log("[realdigitaldefaultaccount.hasrole]");
res = await DREX.realdigitaldefaultaccount.hasrole({
address: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
console.log("[realdigitaldefaultaccount.grantrole]");
res = await DREX.realdigitaldefaultaccount.grantrole({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
console.log("[realdigitaldefaultaccount.revokerole]");
res = await DREX.realdigitaldefaultaccount.revokerole({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0x158eD2632c7c11443d69BAa038aACD7B1D40272B",
role: "move",
});
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Swap One Step Tests
//
-------------------------------------------------------------------------- */
console.log("[swaponestep.executeswap]");
res = await DREX.swaponestep.executeswap({
contractFrom: "Bank1Token",
contractTo: "Bank2Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 100,
});
console.log(res);
console.log("------------------");
console.log("[swaponestep.cbdc]");
res = await DREX.swaponestep.cbdc();
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// Swap Two Steps Tests
//
-------------------------------------------------------------------------- */
console.log("[swaptwosteps.startswap]");
res = await DREX.swaptwosteps.startswap({
contractFrom: "Bank1Token",
contractTo: "Bank2Token",
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
toAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 100,
});
console.log(res);
console.log("------------------");
console.log("[swaptwosteps.executeswap]");
res = await DREX.swaptwosteps.executeswap({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
proposalId: 9,
});
console.log(res);
console.log("------------------");
console.log("[swaptwosteps.cancelswap]");
res = await DREX.swaptwosteps.cancelswap({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
proposalId: 9,
reason: "Incorrect amount",
});
console.log(res);
console.log("------------------");
/* ------------------------------------------------------------------------
//
// STR Tests
//
-------------------------------------------------------------------------- */
console.log("[str.requesttomint]");
res = await DREX.str.requesttomint({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 100,
});
console.log(res);
console.log("------------------");
console.log("[str.requesttoburn]");
res = await DREX.str.requesttoburn({
fromAddress: "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d",
amount: 100,
});
console.log(res);
console.log("------------------");