Metaverse

Metaverse is an open-source public blockchain creating a decentralized ecosystem of digitized assets and identities. Through Blockchain as a Service (BaaS), Metaverse provides enterprises and individuals access to customized, convenient, and secure blockchain services.

How to create a Metaverse transaction using JavaScript

2 min readJan 4, 2018

--

This hands-on tutorial will show you how to create a raw transaction for the Metaverse Blockchain. We will use the MetaverseJS library which you should install using npm.

npm install metaversejs

If you use node.js you need to import the library with require:

var Metaverse = require('metaversejs')

If you want to use the library in a browser you can just import the js file from the dist folder of the npm package.

Now you can start to import your wallet. To import it you need your mnemonic words. In this tutorial we will use the Metaverse testnet. You can also replace the testnet with the mainnet but you should always first test your code on the testnet.

Now you should verify that the generated addresses match with the ones from your wallet. Next you will need to get some testnet ETP. If you dont have testnet ETP you can either get a full node wallet and mine some or you contact anyone from the Metaverse community to give you some.

In order to create the transaction you will need to know the transaction hash of the transaction in which you received the ETP and the index of the output that belongs to you. This output you can then use as an input to the transaction that you want to create. You also need to make sure that you did not use this output in another transaction. Otherwise your transaction will be considered a double spend and get rejected by the network.

Lets say you received 100 million bits (1 ETP) to the address tKXYH2MhpvA3GU7kMk8y3SoywGnyHEj5SB in transaction 5554b27dbf657d008511df56e747ffb2173749fd933b03317cee3c1fde271aea and the output had the index 1 (was the second output of the transacion). To send 0.5 ETP to the address tVpxH8aAa3BAXvbdqUUJwEP6s2ajGKKtyd we will create a transaction with one output of 50 million bits (0.5 ETP) to the recipent address as well as another output to one of our own addresses. The amount of the change output depends on how much network fee we are willing to pay. Usually 10000 bits (0.0001 ETP) are enough. So our change output should have 50,000,000-10,000 = 49,990,000 bits. The difference between the sum of all inputs and the sum of all outputs will be the network fee.

So lets create the transaction. It works very straight forward and all we need to do is to define the inputs and outputs and then use the wallet object from the previous listing and use it to sign the transaction object.

Congratulations! You should now have a signed transaction and see the hex encoded transaction. In order to broadcast the transaction you will need to use a full node wallet and use the sendrawtx command to send it.

--

--

Metaverse
Metaverse

Published in Metaverse

Metaverse is an open-source public blockchain creating a decentralized ecosystem of digitized assets and identities. Through Blockchain as a Service (BaaS), Metaverse provides enterprises and individuals access to customized, convenient, and secure blockchain services.

No responses yet