@railgun-community/waku-relayer-client-web
v6.2.13
Published
This package is meant specifically for browsers.
Downloads
16
Readme
RAILGUN Relayer Client with Waku networking layer
This package is meant specifically for browsers.
yarn add @railgun-community/waku-relayer-client-web
The Basics
// Initialize the Relayer Client
await WakuRelayerClient.start(...)
// Wait for Relayers to connect (5-10 sec) and client to collect fees.
// Relayers broadcast fees through the privacy-safe Waku network.
// Get relayer with lowest fee for a given ERC20 token.
const selectedRelayer = await WakuRelayerClient.findBestRelayer(...)
// Create Relayed transaction and send through selected Relayer.
const relayerTransaction = await RelayerTransaction.create(...)
await RelayerTransaction.send(...)
Webpack configuration
Some dependencies of this package, such as Waku and libp2p, make an assumption that they are running in a Node.js environment. This is not the case in a browser environment, so we need to configure Webpack to ignore some sub-dependencies that are not relevant in the browser.
webpack.config.js
module.exports = {
//...
resolve: {
alias: {
// Waku uses these Node.js-specific sub-dependencies, which we ignore:
'default-gateway': false,
'@achingbrain/nat-port-mapper': false,
}
},
};
If you are using Next.js:
/** @type {import('next').NextConfig} */
module.exports = {
webpack: (config, options) => {
if (options.isServer) {
// If your Next.js component is running in the server, we need to avoid
// loading a WASM module.
config.resolve.alias['@railgun-community/curve25519-scalarmult-wasm'] =
'@railgun-community/curve25519-scalarmult-rsjs';
} else {
// If your Next.js component is running in the browser, we need to avoid
// loading some modules which call Node.js APIs such as `child_process`.
config.resolve.alias['default-gateway'] = false;
config.resolve.alias['@achingbrain/nat-port-mapper'] = false;
}
return config;
},
};