const Web3 = require('web3');
//You must compile the smart contracts or use the official ABIs of the repository
const MoC = require('../../build/contracts/MoC.json');
const truffleConfig = require('../../truffle');
* Get a provider from truffle.js file
* @param {String} network
const getDefaultProvider = network =>
truffleConfig.networks[network].provider || truffleConfig.networks[network].endpoint;
* Get a gasPrice from truffle.js file
* @param {String} network
const getGasPrice = network => truffleConfig.networks[network].gasPrice || 60000000;
* Get a new web3 instance from truffle.js file
const getWeb3 = network => {
const provider = getDefaultProvider(network);
return new Web3(provider, null, {
transactionConfirmationBlocks: 1
const web3 = getWeb3('rskTestnet');
const gasPrice = getGasPrice('rskTestnet');
//Loading MoC address on testnet
const mocAddress = '<contract-address>';
const execute = async () => {
web3.eth.defaultGas = 2000000;
* Loads an specified contract
* @param {ContractABI} abi
* @param {String} contractAddress
const getContract = async (abi, contractAddress) => new web3.eth.Contract(abi, contractAddress);
const moc = await getContract(MoC.abi, mocAddress);
throw Error('Can not find MoC contract.');
const redeemDocRequest = async docAmount => {
const [from] = await web3.eth.getAccounts();
const weiAmount = web3.utils.toWei(docAmount, 'ether');
console.log(`Calling redeem Doc request, account: ${from}, amount: ${weiAmount}.`);
.redeemDocRequest(weiAmount)
.send({ from, gasPrice }, function(error, transactionHash) {
if (error) console.log(error);
if (transactionHash) console.log('txHash: '.concat(transactionHash));
.on('transactionHash', function(hash) {
console.log('TxHash: '.concat(hash));
.on('receipt', function(receipt) {
.on('error', console.error);
const docAmount = '10000';
await redeemDocRequest(docAmount);
.then(() => console.log('Completed'))
console.log('Error', err);