RenJS Class
RenJS (TypeDoc)​
The RenJS
class provides methods for creating and configuring gateways.
It's initialized by providing a network or a RenVM provider. Generally, your program or website should only have one RenJS instance per network.
import RenJS from "@renproject/ren";
import { RenNetwork } from "@renproject/utils";
import { RenVMProvider } from "@renproject/provider";
import { JsonRpcProvider } from "@renproject/provider/build/main/rpc/jsonRpc";
// Mainnet - the following are equivalent:
new RenJS();
new RenJS("mainnet");
new RenJS(RenNetwork.Mainnet);
new RenJS("https://rpc.renproject.io");
new RenJS(new RenVMProvider("mainnet"));
new RenJS(new RenVMProvider("https://rpc.renproject.io"));
new RenJS(new RenVMProvider(new JsonRpcProvider("https://rpc.renproject.io")));
// Testnet
new RenJS("testnet");
The second parameter for RenJS
allows you to pass in some additional configuration:
import RenJS from "@renproject/ren";
import { LogLevel } from "@renproject/ren";
new RenJS("mainnet", {
// Configure a logger:
logLevel: LogLevel.Debug,
logger: console,
// Configure network delay for monitoring gateway addresses:
networkDelay: 15000, // 15 seconds
});
Before creating a gateway or fetching fees, you'll need to connect the chain classes to RenJS:
import RenJS from "@renproject/ren";
import { Bitcoin, Ethereum } from "@renproject/chains";
const bitcoin = new Bitcoin({ network: "testnet" });
const ethereum = new Ethereum({ network: "testnet", signer: ... });
const renJS = new RenJS("testnet")
.withChains(bitcoin, ethereum);
// Equivalently:
renJS.withChains([bitcoin, ethereum]);
renJS.withChain(bitcoin).withChain(ethereum);
You can now use the various fields and methods available on RenJS:
Methods
getChain - for getting the chain instances added with withChains
getFees - for estimating gateway fees (see fees)
gateway - for creating Gateways
gatewayTransaction - for re-creating Gateway Transactions created by a Gateway
selectShard - for fetching an asset's associated RenVM shard (currently there's only one shard)
defaultTransactionHandler - a static method that you can pass to a gateway.on("transaction")
Properties
provider - the connected RenVM provider