concordium-web-sdk
Wrappers for interacting with the Concordium node, for the web environment.
Please see the documentation for more information
Table of Contents:
ConcordiumGRPCWebClient
The SDK provides a gRPC client, which can interact with the Concordium Node using gRPC-web.
For an overview of the endpoints, click here.
To create a client, the ConcordiumGRPCWebClient class can be used. It
requires the address and port of the concordium node.
import { ConcordiumGRPCWebClient } from '@concordium/web-sdk';
...
return new ConcordiumGRPCWebClient(
address,
port,
{ timeout: 15000 }
);
The fourth argument is additional options. In the example above we sat the timeout for a call to the node to 15 seconds. The options allowed here are those allowed by the grpcweb-transport.
ConcordiumGRPCNodeClient
Note that this can ONLY be used in a nodeJS environment
The SDK provides a gRPC client, which can interact with the Concordium Node using gRPC.
For an overview of the endpoints, click here.
To create a client, the ConcordiumGRPCNodeClient class can be used. It
requires the address and port of the concordium node.
import { ConcordiumGRPCNodeClient, credentials } from '@concordium/web-sdk/nodejs';
...
const creds = ...; // e.g. credentias.createInsecure();
return new ConcordiumGRPCWebClient(
address,
port,
creds,
{ timeout: 15000 }
);
Like with the grpc web client, the fourth argument is additional options.
React native
To use the SDK in a react native context, it is required to include some polyfills for functionality used in the SDK.
The list of polyfills to be installed in the project alongside @concordium/web-sdk include:
{
...
"dependencies": {
"@azure/core-asynciterator-polyfill": "...",
"@stardazed/streams-polyfill": "...",
"react-native-get-random-values": "...",
"react-native-polyfill-globals": "...",
"text-encoding": "..."
}
}
Installation
yarn add @concordium/web-sdk react-native-polyfill-globals react-native-get-random-values text-encoding @azure/core-asynciterator-polyfill @stardazed/streams-polyfill # or npm install
npx pod-install # if building for ios, adds native modules from dependencies to project.
Building App
The initial app build may take a significant amount of RAM (up to 10Gb), due to converted wasm module to js code.
If you encounter the error Reached heap limit Allocation failed - JavaScript heap out of memory
You need to increase memory limit NODE_OPTIONS=--max-old-space-size
Example of start script in package.json
{
"start": "NODE_OPTIONS=--max-old-space-size=12288 react-native start"
}
Adding polyfill to app
// polyfill.js
import '@stardazed/streams-polyfill';
import '@azure/core-asynciterator-polyfill';
import { polyfill as polyfillEncoding } from 'react-native-polyfill-globals/src/encoding'; // Requires peer dependency `text-encoding`
import { polyfill as polyfillCrypto } from 'react-native-polyfill-globals/src/crypto'; // Requires peer dependency `react-native-get-random-values`
polyfillEncoding();
polyfillCrypto();
// index.js
import { AppRegistry } from 'react-native';
import './polyfill'; // polyfills must be added before ./App
import App from './App';
import { name as appName } from './app.json';
AppRegistry.registerComponent(appName, () => App);
This ensures the native modules required by the SDK are present.