An open source JS integration library for REMChain, simplifying the access and interaction with REMME nodes both public or permissioned.
You can check out how to do that at REMME core repo. Note: you can enable/disable methods by modifying REMME_REST_API_AVAILABLE_METHODS eviroment variable at the .env file.
npm install remme
yarn add remme
Use the prebuild dist/remme.min.js
, or
build using the [remme][repo] repository:
npm run build
Then include dist/remme.min.js
in your html file.
This will expose Remme
on the window object.
Describe:
Our library use protobuf.js to work with protobufs.
So for usage with Typescript you may get this error.
Solution:
- You need to install @types/long.
- You need to import Long before import remme library
Describe:
Our library use crypto nodejs package for working with hash.
So for usage with Typescript you may get this error.
Solution:
web3/web3.js#1555 (comment)
- open node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js
- Find "node: false", and change it to "node: {crypto: true, stream: true}"
Describe:
Our library use sawtooth-sdk package.
So for usage with React you may get this error if you build app.
Issue: hyperledger-archives/sawtooth-sdk-javascript#4
Solution:
- npm run eject
- npm i uglifyjs-webpack-plugin@1.3.0
- In webpack.config.prod.js you need import this package and use it:
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
// ...
// Find string: "Minify the code."
// Comment or remove new webpack.optimize.UglifyJsPlugin with all configuration after this string.
// And provide next string:
new UglifyJsPlugin(),
const Remme = require("remme");
// import Remme from "remme";
const privateKeyHex = "7f752a99bbaf6755dc861bb4a7bb19acb913948d75f3b718ff4545d01d9d4f10";
const networkConfig = {
nodeAddress: "localhost",
nodePort: "8080",
sslMode: false,
};
const remme = new Remme.Client({ privateKeyHex, networkConfig });
const { RemmeFamilyName } = require("remme-utils");
const someAccountPublicKeyInHexFormat = "0306796698d9b14a0ba313acc7fb14f69d8717393af5b02cc292d72009b97d8759";
const someRemmeAddress = generateAddress(RemmeFamilyName.Account, someAccountPublicKeyInHexFormat);
const balance = await remme.token.getBalance(someRemmeAddress);
console.log(`Account ${someRemmeAddress} balance - ${balance} REM`);
const transactionResult = await remme.token.transfer(someRemmeAddress, 100);
console.log(`Sending tokens...BatchId: ${transactionResult.batchId}`);
const transactionCallback = async (err, result) => {
if (err) return;
console.log("token", result);
const newBalance = await remme.token.getBalance(someRemmeAddress);
console.log(`Account ${someRemmeAddress} balance - ${newBalance} REM`);
transactionResult.closeWebSocket()
};
transactionResult.connectToWebSocket(transactionCallback);
const certificateTransactionResult = await remme.certificate.createAndStore({
commonName: "userName1",
email: "user@email.com",
name: "John",
surname: "Smith",
countryName: "US",
validity: 360,
serial: "some serial"
});
const certificateTransactionCallback = async (err, response) => {
if (err) return;
console.log("certificate", response);
console.log(`Certificate was saved on REMchain at block number: ${response.block_number}`);
const certificateStatus = await remme.certificate.check(certificateTransactionResult.certificate);
console.log(`Certificate IsValid = ${certificateStatus.valid}`);
certificateTransactionResult.closeWebSocket();
};
certificateTransactionResult.connectToWebSocket(certificateTransactionCallback);
RemmeEvents is enums which describe all available events.
import { RemmeEvents } from "remme-web-socket-events";
remme.events.subscribe({
events: RemmeEvents.SwapInit
}, (err, res) => {
if (err) {
console.log(err);
return;
}
console.log(res);
})
Also we give a possibility to start listen events from previous block by providing last known block id
import { RemmeEvents } from "remme-web-socket-events";
remme.events.subscribe({
events: RemmeEvents.SwapInit,
lastKnownBlockId: "db19f0e3b3f001670bebc814e238df48cef059f3f0668f57702ba9ff0c4b8ec45c7298f08b4c2fa67602da27a84b3df5dc78ce0f7774b3d3ae094caeeb9cbc82"
}, (err, res) => {
if (err) {
console.log(err);
return;
}
console.log("events", res);
});
Unsubscribe from listening events
remme.events.unsubscribe();
REMME software and documentation are licensed under Apache License Version 2.0 <LICENSE>
_.