How to Integrate VIP-191 (II) — User's Side

  1. The “user” creates a transaction body.
  2. The “user” generates a “user signature”.
  3. The transaction is sent to a “sponsor” to get a “sponsor signature”.
  4. The two signatures are combined to forge a “final signature”.
  5. The final transaction is posted to the VeChain network.
Overview of VIP-191 Fee Delegation.

Deploy the Smart Contract

First, we need to deploy a simple contract on test-net for us to interact with. The source code of the smart contract is as simple as below. It contains a counter variable which will be increased each time the function increaseAmount is called by any user.

https://gist.github.com/laalaguer/5d7dd6889e70e8784f4448f529dc8976

Build a Transaction Body

We employ the thor-devkit.js library to help us with the building of a transaction. To call the method, we build a simple transaction like this:

https://gist.github.com/laalaguer/4aa1787887cc7d5aa23c85dd2a59d1d9

Generate a User Signature

Since the user wants to call the smart contract, a signature from the user is required. We import an empty wallet and generate a “user signature” of the transaction.

https://gist.github.com/laalaguer/1eaea9354eb2deba769a92296814e4f1

Get a Sponsor Signature

This step requires us to send the original transaction to the sponsoring service and let the sponsor generate a signature for us. On the user’s side, the network operation is can be wrapped into a getSponsorSignature function:

Next Steps

If you have followed the above steps faithfully, then the job on the user’s side is almost done. The remote sponsor needs to react to the request and return the signature or reject it. We will continue in the next tutorial about:

  • Write a sponsor service to generate “sponsor signature”.
  • Combine the user signature with the sponsor’s signature.
  • Assemble the final transaction and post to the VeChain network.

Continue Reading:

--

--

Passion in computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store