Skip to main content

Integrating with Ren contracts

tip

For now, integrating with Ren contracts is only documented for EVM chains and Solidity.

The RenJS Tutorial goes through writing a smart contract that can mint Ren-tokens.

There is also the Ren Solidity Template repository includes local tests that test a mint function using RenJS and a mock RenVM provider.

Solidity

Importing Ren contracts

The Ren contracts can be imported with the following packages:

Note that they currently require an older Solidity compiler version - 0.5.17. You can configure Hardhat to use multiple Solidity versions by adding the following line to the networks field in hardhat.config.ts:

  solidity: {
compilers: [
{
version: "0.8.4",
},
{
version: "0.5.17",
},
],
},

You can then import contracts in Solidity like so:

import {GatewayRegistry} from "@renproject/gateway-sol/contracts/Gateway/GatewayRegistry.sol";

Writing a mint function

In order for a contract to be compatible with how RenJS submits mints, the function being called must follow the following standard:

function functionName(

// Normal parameters - can be any number and types
uint256 _param1,
uint256 _param2,

// Parameters from RenVM
uint256 _amount,
bytes32 _nHash,
bytes calldata _sig

) external {

// ... your code

// Hash parameters. All parameters besides _amount, _nHash and _sig should be included.
bytes32 pHash = keccak256(abi.encode(_param1, _param2));

// Mint Ren-asset. The returned value is how much was minted, after subtracting RenVM fees.
uint256 mintedAmount = registry.getGatewayBySymbol("BTC").mint(pHash, _amount, _nHash, _sig);

// ... your code

}

If you want to support multiple Ren-assets, then you can pass in a _symbol parameter anywhere in the parameters (before the _amount parameter) and pass it to getGatewayBySymbol.

Testing on a local network

See Ren Solidity Template.