Main Contract
Search…
How-to
In the following sections we will give some code on how this can be done through a Smart Contract or directly, with a console or with an app. ​

Smart Contract​

To create a new Smart Contract that uses the Money On Chain platform, you can use any language and IDE you want. In this tutorial, we will show you how to do it using Solidity language, Truffle Framework and NPM. Truffle framework offers some template projects that you can use to develop applications that use smart contracts. You can get more information here. Assuming you already have your project up and running (if you don't, please follow this link) the only extra thing you need to do is to install our repo as a dependency in your NPM project. In order you need to do this you just need to run the following command. ​
1
npm install --save -E git+https://[email protected]/money-on-chain/main-RBTC-contract.git
Copied!
Having done that lets you use our contract as a dependency to your contract. For this let's suppose you are doing some kind of contract that when executing a certain task charges a fixed commission. Now let's suppose that the commission is sent in RBTCs because it is easier for the user but actually you want some DOCs. The good news is that you can do this instantly just by redeeming them. The code necessary to do this is actually pretty simple. ​ You just have to import the contract ​
1
import 'money-on-chain/contracts/MoC.sol';
Copied!
Receive the address in the constructor in order to be able to interact with it later, and the vendorAccount address needed to do the operation
1
constructor (MoC _mocContract, address vendorAccount, rest of your params...) {
2
//....rest of your constructor....
3
}
Copied!
1
//Create a new redeem request
2
uint256 docAmount = 90;
3
moc.redeemDocRequest(docAmount);
Copied!
1
//Add 10 docs to a redeem request.
2
moc.alterRedeemRequestAmount(true, 10);
3
//Sustract 5 docs to a redeem request.
4
moc.alterRedeemRequestAmount(true, 5);
Copied!
1
//Trying to redeem All Docs.
2
uint256 docBalance = docToken.balanceOf(userAddress);
3
moc.redeemFreeDocVendors(docBalance, vendorAccount);
Copied!
You can send it immediately to you so you can start using it right away. In order to do this you should add a few more lines similar to the ones before, only that you will have to use the bpro token. ​ This will leave you with a contract similar to the following ​​
1
pragma solidity ^0.5.8;
2
import "money-on-chain/contracts/MoC.sol";
3
import "money-on-chain/contracts/token/DocToken.sol";
4
// Here you will import your own dependencies
5
6
contract YourRedeemingDocContract {
7
// Address of the MoC contract
8
MoC public moc;
9
// Address of the bitpro token
10
DocToken public doc;
11
// DOC Amount
12
uint256 docAmount;
13
// Address that will receive the markup
14
address public vendorAccount;
15
// rest of your variables
16
17
constructor (MoC _moc, DocToken _doc, uint256 _docAmount, address _vendorAccount) public {
18
moc = _moc;
19
doc = _doc;
20
docAmount = _docAmount;
21
vendorAccount = _vendorAccount;
22
// You could have more variables to initialize here
23
}
24
25
function createRedeemRequest() public {
26
uint256 previousBalance = doc.balanceOf(msg.sender);
27
moc.redeemDocRequest(docAmount);
28
uint256 newBalance = doc.balanceOf(msg.sender);
29
}
30
31
function addToRedeemRequest(uint256 _addValue) public {
32
moc.alterRedeemRequestAmount(true, docAmount);
33
uint256 newBalance = doc.balanceOf(msg.sender);
34
}
35
36
function sustractToRedeemRequest(uint256 _addValue) public {
37
moc.alterRedeemRequestAmount(false, docAmount);
38
uint256 newBalance = doc.balanceOf(msg.sender);
39
}
40
41
function redeemFreeDoc(uint256 _docAmount) public {
42
uint256 previousBalance = doc.balanceOf(msg.sender);
43
moc.redeemFreeDocVendors(_docAmount, vendorAccount);
44
uint256 newBalance = doc.balanceOf(msg.sender);
45
}
46
// rest of your contract
47
}
Copied!
And that is it, the only thing left to do is to add in the Truffle migrations scripts the address to MoC and BPro when deploying YourRedeemingDocContract and you are done.
Last modified 3mo ago
Copy link