How Vechain MPP works and how to use it

MiRei
6 min readOct 6, 2019

Recently I was updating some code of mine to support Vechains VIP191 feature. While I was implementing the necessary changes I realized, that I doesn’t even really understand the MPP feature. I mean, I’ve read the articles, I understand the concept, I know what happens on the blockchain, but I didn’t know what actually happens inside a contract.

I sat down and read the available information again. I found some refreshing information but nothing like “Ahhh, that’s how it works. ”

Best sources are:

I then decided to try and deploy a simple token contract using MPP. First thing I’ve done was to power up my solo-developemt-environment and after two coffee-intensive nights I can say: Well done, Vechain! Well done.

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:

Modify the token source code to use MPP

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

Setting up the wallets in sync

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.

  1. Initiator wallet: This wallet is used to register the new contract on the blockchain and will automatically become master of all MPP functions.
  2. Sponsor wallet: This wallet will be used to sponser interactions for the token contract.
  3. User wallet 1: A wallet with no vet/vthor at all.
  4. User wallet 2: A wallet with vet/vthor.
VeChain MPP demo wallet setup
Successful request for vet/vthor

Deploy new token to testnet

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.

Compiled smart contract, ready to deploy

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

MPP activated smart-contract on the VeChain Testnet

Making Sync aware of the new contract

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).

Adding custom contract to Sync

After that, Sync can use all functions of that contract (including the MPP features).

Custom contract with all read and write functions

Setting up MPP

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”.

Registering as a sponsor for a smart contract

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 sponsor

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

Setting CreditPlan for sponsoring

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.

Adding users to be sponsored

Distributing token to user wallets

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”.

Transfering token from Initiator to user

The big moment — using MPP!

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.

Sending a transaction from a empty wallet using MPP

Transaction done on Testnet: click

Successful usage of the MPP feature

Conclusion: MPP gives a hole level of new opportunity

After spending some time with this, I realised how much can be done with this feature. From giving new users a credit to start, over giving active users (or XNodes) a benefit using the serivce to completely sponsoring 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.

--

--