Install using npm:
npm install metaversejs
let Metaverse = ;
For use in webapps the npm package contains a dist/metaverse.min.js. You can generate this file from source using grunt.
Please also check the examples folder.
let Metaverse =let number_of_addresses = 10Metaversewallet
This will generate a new random wallet and return the mnemonic words as well as the first 10 addresses of the wallet.
Send ETP or MST
As Metaverse is UTXO based you need to specify the inputs and outputs of the transaction. The following example creates a basic P2PKH (pay to public key hash) transaction.
//Transaction objectvar tx =//Add inputstx//Add outputstxtxconsole//Sign the inputswallet
You can also add other assets to the transaction. The resulting raw transaction can be broadcasted to any blockchain nodes.
Another way for creating transactions is to use the transaction builder.
const target ="ETP": 100000000"MST":"MVS.HUG": 5Metaversetransaction_builder
For standard transaction the transaction builder is the preferred way so the next examples will use the transaction builder only.
In order to create a deposit and get interest you just have to add a lock output to a transaction. Possible values for the duration are: 25200, 108000, 331200, 655200 and 1314000 blocks on the mainnet.
The reward transaction will be generated by the miner of the block that will contain the transaction.
In order to issue a new asset add an asset issue output to a transaction. Please make sure that the asset symbol is unique. Precision must be in range 0..19 and the maximum supply is must be provided as a quantity of the smallest unit. An asset with 1000 tokens that should have a precision of 2 decimals must be provided as 1000000 and precision 2. The transaction fee must be 10 ETP.
Send to multiple recipients
const recipients = address: "xxx" "target": "ETP": 123 "MST": "SDG": 18 "avatar": "EricGu"Metaversetransaction_builder
To attach a message to any transaction there is a function called addMessage. If you use the transaction builder you can use the messages parameter to add an array of messages that will be added to the transaction. For manual addition of messages you can do the following:
//Transaction objectvar tx = ;//Add inputstx;//Add messagetx;//Don't forget the changetx;
You can also easily decode a hex encoded transaction.
Not all information about the previous outputs of the inputs are enoded in a raw transaction. If you want to encode the transaction again you have to add the missing values to the inputs.
To run the unit tests just execute: