How Vechain MPP works and how to use it – MiRei

In the next few minutes, I will describe my way to a working MPP-token-contract on testnet. To to this, I needed the following tools:
This part is really awesome. I was prepared to do some serious copy/pasting and to really deep-dive into smart contract coding but I didn’t even know where to start exactly. So I turned to Ken Woodruff from RealItems.org and asked for guidance. We had a really good and informative chat and he gave me some very nice insights into MPP. After some testing, I was able to narrow it down to two lines. All it took to modify a etherum ERC20 token contract to use VeChains MPP feature were TWO LINES!
Vechain Thor has builtin contracts that can simply be imported into any contract and that will actually do all the work. So all it needed inside the solidity code was:
//Import the contracts
import “./builtin.sol”;
and
// Use the loaded contract in token contract
using Builtin for CONTRACTNAME;
Check here for the complete smart-contract: click
In order to push the contract to the Testnet, I need some VTHO. So next thing I did was setting up the wallets related to the contract in Sync and loading them with VET/VETH from the VeChainTestnet Faucet at https://faucet.vecha.in.
- Initiator wallet: This wallet is used to register the new contract on the blockchain and will automatically become master of all MPP functions.
- Sponsor wallet: This wallet will be used to sponser interactions for the token contract.
- User wallet 1: A wallet with no vet/vthor at all.
- User wallet 2: A wallet with vet/vthor.
In Ethereum I can use https://remix.ethereum.org to develop and deploy source code. VeChain hast a very similar portal at https://vechainstore.com and it can use Coment and Connex! After installing Comet, importing the “Initiator wallet” and switching to Testnet, vechainstore.com will recognize Comet and I can push the contract directly into the Testnet (For this contract the tokensupply must be set during deployment)… Amazingly easy.
After pressing “Deploy” and waiting for the ten-second blocktime to pass, I could see my deployed contract. There is now a token called “MPP Token” on the testnet: here
Sync has an App called “Inspector”. With that, I can interact with the new contract. But first Inspector must be made aware of the contract by adding the token address and the ABI (ABI can be found in https://vechainstore.com after I compiled the contract).
After that, Sync can use all functions of that contract (including the MPP features).
All MPP settings can be found in “Prototype-Read” and “Prototype-Write”. In here this feature is called “sponsoring”. This was a little confusing for me, so I will dive in a little deeper. To activate sponsoring for the contract the following steps need to be done:
- Register a sponsor (must be done from the sponsor wallet)
- Activate a sponsor (must be done from the initiator wallet)
- Activate a credit plan (must be done from the initiator wallet)
- Register users that can use sponsoring (must be done from the master wallet)
Register a sponsor
After deploying the contract, the sponsoring feature is available but will not be active. To make the “Sponsor wallet” the sponsor of this contract, the “Sponsor wallet” needs to register for it. Simply done by executing the “sponsor” function from the “Sponsor wallet”.
Activate a sponsor
The new sponsor is now availible inside the contract but is still not active. To activate the sponsor, the Account Master (Initiator wallet) needs to set it via “selectSponsor”. This way, sponsoring wallets can change over time. Very thoughtful.
Activate a credit plan
This took me nearly two hours to figure out…
The details about CreditPlan can be read here but to make it short:
I can set a recovery rate and credit for every user. That way I can limit the amount of vthor a user can burn and how long it will take to recover this credit.
For this demo, I set the credit to 300 VTHO and the recovery rate to 300 VTHO/day. So a user can spend 300 VTHO every day. According to the prototype documentation these values need to be set in Wei and Blocks (Yea, I missed that one hard) and according to the builtin-contracts 1 VTHO = 1e18 Wei (1.000.000.000.000.000.000).
300 VTHO = 300.000.000.000.000.000.000 WEI
300 VTHO/8640Blocks = 0,0347VTHO/Block = 34.700.000.000.000.000 WEI/Block
Register users that can use sponsoring
Now all I need to do is to allow user-addresses to use the sponsoring. Every address has to be added by the account master (Initiator wallet). In this demo “User wallet 1” and “User wallet 2” will be added. By doing this, the contract will prevent abusing the sponsoring feature.
Now sponsoring is active for the two “User wallets” (not for “Initiator wallet”). To see if the “User wallets” can interact using MPP, they need some token. This can also be done using Inspector. The contract has 18 decimal digits, so 100 tokens equals 100.000.000.000.000.000.000 for “numTokens”.
“User wallet 1” does not have any VET or VTHOR but I can now use this wallet to send tokens to another wallet. Although Sync notifies me that there is not enough energy on that account, the transaction will be valid using MPP from the “Sponsor wallet” and get inside a block.
Transaction done on Testnet: click
After spending some time with this, I realised how much can be done with this feaure. From giving new users a credit to start, over giving active users (or XNodes) a benefit using the serivce to completely sposoring and hiding the whole blockchain process for the user this feature is really incredible for interaction with blockchain. As said earlier: Well done, Vechain! Well done.
Published at Sun, 06 Oct 2019 11:42:06 +0000
{flickr|100|campaign}
