Integrate with Ethers.js
Integrate directly from your website / (d)app
What is Ethers.js ?
Set Up
import { ethers } from "ethers";
const xchfAddress = "0xb4272071ecadd69d933adcd19ca99fe80664fc08";
const xchfABI = ["function Approve(address spender, uint256 amount)"];
const shareAddress = "0x6f38e0f1a73c96cb3f42598613ea3474f09cb200";
const shareABI = [
"function transferAndCall(address recipient, uint amount, bytes calldata data)",
"function recovery() view returns (address)",
"function declareLost(address collateralType, address lostAddress)"
];
let paymentHubAddress;
const paymentHubABI = [
"function approveERC20(address erc20In)",
"function getPriceInERC20(uint256 amountInBase, bytes memory path) view returns (uint256)",
"function getPriceInEther(uint256 amountInBase, IBrokerbot brokerBot) view returns (uint256)",
"function payFromEtherAndNotify(IBrokerbot recipient, uint256 amountInBase, bytes calldata ref)",
"function payFromERC20AndNotify(address recipient, uint256 amountBase, address erc20, uint256 amountInMaximum, bytes memory path, bytes calldata ref)",
"function payAndNotify(address recipient, uint256 amountInBase, bytes calldata ref)"
];
let brokerbotAddress;
const brokerbotABI = [
"function paymenthub() view returns (address)",
"function getBuyPrice(uint256 shares) view returns (uint256)",
"function settings() view returns (uint256)"
];
let recoveryHubAddress;
const recoveryHubABI = [
"function declareLost(address token, address collateralType, address lostAddress)"
];
const brokerbotRegistryAddress = "0xcB3e482df38d62E73A7aE0E15a2605caDcc5aE98";
const brokerbotRegistryABI = ["function getBrokerbot(address base, address token) view returns (address)"];
const amountOfShares = 100;
const buyEnabled = 0x1;
async function main() {
// get a RPC provider
const ethersProvider = new ethers.providers.InfuraProvider();
// get a signer
const wallet = ethers.Wallet.createRandom().connect(ethersProvider);
// get contract instances
const xchfContract = new ethers.Contract( xchfAddress , xchfABI, wallet);
const shareConract = new ethers.Contract(shareAddress, shareABI, wallet);
const brokerbotRegistryContract = new ethers.Contract(brokerbotRegistryAddress, brokerbotRegistryABI, wallet);
brokerbotAddress = await brokerbotRegistryContract.getBrokerbot(xchfAddress, shareAddress);
const brokerbotContract = new ethers.Contract(brokerbotAddress, brokerbotABI, wallet);
paymentHubAddress = await brokerbotContract.paymenthub();
const paymentHubContract = new ethers.Contract(paymentHubAddress, paymentHubABI, wallet);
///.... include here the example calls Getting Price for Buying Shares
Check if Buying is Enabled in Brokerbot Setting
Buying Shares
Selling Shares
Create an Offer
Initiate Recovery
The Full Script
Last updated