Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ This is a Metaverse Tutorial series

This is a series of Metaverse tutorials. To begin clone this repository

```
```bash
git clone https://github.com/antron3000/MetaverseTutorials.git

```

navigate to the tutorial directory

```
```bash
cd MetaverseTutorials
```

update your repo to the latest version of mvs-blockchain-js
```
```bash
git submodule update --init --recursive
```

Install the metaverse npm package

```
```bash
npm install metaversejs --save
```

Install the mvs-blockchain-js npm package
```
```bash
cd mvs-blockchain-js && npm install
```

Expand Down Expand Up @@ -65,7 +65,7 @@ Please follow the Environment setup instructions below before starting.

Start by entering the "playground" directory. This is where you can build ALL your Metaverse apps during the tutorial.

```
```bash
cd tutorials/playground
```

Expand All @@ -82,7 +82,7 @@ For use in nodejs scripts, import mvs-blockchain from the mvs-blockchain folder,

Inside the testscript, add:

```
```javascript
//import mvs-blockchain-js
let blockchain = require('../../mvs-blockchain-js')({
url: "https://explorer-testnet.mvs.org/api/"
Expand All @@ -102,20 +102,20 @@ console.log("Metaversjs has been successfully imported!")

now run

```
```bash
node testScript.js
```

**Interact with metaverse via webapp**

First create an html file
```
```bash
touch index.html
```

and add

```
```html
<html>
<head>
<meta charset="utf-8">
Expand All @@ -128,28 +128,27 @@ and add

```

To interact with webapps you must generate "index.js" from mvs-blockchain-js and "metaverse.min.js" from metaversejs. To generate these files you must clone each repository separately, namely [metaversjs](https://github.com/canguruhh/metaversejs) and [mvs-blockchain-js](https://github.com/mvs-org/mvs-blockchain-js) and simply run

To interact with webapps you must generate "index.js" from mvs-blockchain-js and "metaverse.min.js" from metaversejs. To generate these files you must clone each repository and simply run

```
```bash
grunt
```

This will generate javascript files into the /dist folder that you can import into your app. You don't have to worry about this for now. We have generated these files and placed them in the playground folder. To include them in your webapp just add these script tags into your html page.

```
```html
<script src = "metaverse.min.js"></script>
<script src = "index.min.js"></script>
```

Serve your webpage
```
```python
python -m SimpleHTTPServer 4444
```

To test that the libraries have been successfully imported into your webpage, open the web console and enter

```
```javascript
blockchain = await Blockchain({url: "https://explorer-testnet.mvs.org/api/"})

blockchain
Expand Down
58 changes: 32 additions & 26 deletions examples/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let blockchain = require('../mvs-blockchain-js')({
let Metaverse = require('metaversejs');

var wallet
var mnemonic = "van juice oak general lyrics gravity hammer shield over eager crew volume survey join lonely purchase kitten artwork mass cousin process mixture add knife"
var mnemonic = "butter vacuum breeze glow virtual mutual veteran argue want pipe elite blast judge write sand toilet file joy exotic reflect truck topic receive wait"
var addresses
var balances

Expand All @@ -21,8 +21,8 @@ async function run(){
console.log(balances)

console.log("Sending ETP..............")
let amountToSend = 10000000
//await sendETP(amountToSend)
let amountToSend = 10
await sendETP(amountToSend)
console.log("ETP Sent")

console.log("Depositing ETP............")
Expand All @@ -32,38 +32,38 @@ async function run(){
console.log("ETP deposited")

console.log("Registering Avatar............")
let avatarName = "testguy3"
let avatarAddress = wallet.getAddress(0)
let avatarName = "canfr"
let avatarAddress = wallet.getAddress(2)
//await registerAvatar(avatarName,avatarAddress)
console.log("avatar " + avatarName + " Registered to " + avatarAddress)

console.log("getting Avatar Info......")

let avatarInfo = await getAvatarInfo("Tal")
let avatarInfo = await getAvatarInfo("PEI")
console.log(avatarInfo)

console.log("Issuing MST.............")
let issuingAddress = wallet.getAddress(0),
symbol = 'COOOL',
let issuingAddress = wallet.getAddress(2),
symbol = 'AABBCCDD',
max_supply = 100000,
precision = 8,
issuer = 'testguy3',
issuer = 'cangr',
description = 'cool asset is cool';
//await issueMST(issuingAddress,symbol,max_supply,precision,issuer,description)

console.log("Transferring MST.............")
var target = {
"COOOL": 1
};
await sendMST(target)
//await sendMST(target)
console.log("MST Sent")


console.log("Registering MIT................")


let MITsymbol = "testar2"
let avatar = "testguy3"
let MITsymbol = "sestMIT334"
let avatar = "cangr"
let content = "some test content"
//await issueMIT(avatar,MITsymbol,content)

Expand All @@ -72,10 +72,10 @@ async function run(){

console.log("Transferring MIT................")

let MITToSend = "testar"
let sender_avatar = "testguy3"
let MITToSend = "sestMIT334"
let sender_avatar = "cangr"
let recipient_avatar = "Tal"
await sendMIT(sender_avatar,recipient_avatar,MITToSend)
//await sendMIT(sender_avatar,recipient_avatar,MITToSend)

}

Expand All @@ -101,7 +101,6 @@ async function getBalances(){

let height = await blockchain.height()
let txs = await blockchain.addresses.txs(wallet.getAddresses())
console.log(txs)
let utxo = await Metaverse.output.calculateUtxo(txs.transactions, wallet.getAddresses())
let balances = await blockchain.balance.all(utxo, wallet.getAddresses(), height)

Expand Down Expand Up @@ -226,12 +225,12 @@ async function issueMIT(issuer_avatar,symbol,content){
ETP: 10000
};

let recipient_address = wallet.getAddress(0)
let change_address = wallet.getAddress(0)
let recipient_address = wallet.getAddress(2)
let change_address = wallet.getAddress(2)

let height = await blockchain.height()
let txs = await blockchain.addresses.txs(wallet.getAddresses())
let utxos = await Metaverse.output.calculateUtxo(txs.transactions, wallet.getAddresses()) //Get all utxo
let utxos = await Metaverse.output.calculateUtxo(txs.transactions, [recipient_address]) //Get all utxo
let result = await Metaverse.output.findUtxo(utxos, {}, height,10000) //Collect utxo to pay fee of 0.0001 ETP
let tx = await Metaverse.transaction_builder.registerMIT(result.utxo, recipient_address, issuer_avatar, symbol, content, change_address, result.change)
tx = await wallet.sign(tx)
Expand All @@ -244,21 +243,28 @@ async function issueMIT(issuer_avatar,symbol,content){

async function sendMIT(sender_avatar,recipient_avatar,symbol){


let recipient_address = getAvatarAddress(recipient_avatar)
let change_address = getAvatarAddress(sender_avatar)
let recipient_address = await getAvatarAddress(recipient_avatar)
let sender_address = await getAvatarAddress(sender_avatar)
let change_address = sender_address
console.log(recipient_address)
console.log(symbol)
console.log(sender_address)
let height = await blockchain.height()
let txs = await blockchain.addresses.txs(wallet.getAddresses())
let utxos = await Metaverse.output.calculateUtxo(txs.transactions, wallet.getAddresses()) //Get all utxo
let utxos = await Metaverse.output.calculateUtxo(txs.transactions, [sender_address]) //Get all utxo
//console.log(utxos)

console.log(wallet.getAddresses())
let results = await Promise.all([
Metaverse.output.findUtxo(utxos, {}, height),
Metaverse.output.filter(utxos, {
type: "mit"
symbol: "sestMIT334"
})
])
//console.log(results)
console.log(results)
//console.log(results[0])
console.log(results[0].utxo.concat(results[1]))
console.log( "sc7c")
//console.log(results[0].utxo.concat(results[1]))
let tx = await Metaverse.transaction_builder.transferMIT(results[0].utxo.concat(results[1]), sender_avatar, recipient_address, recipient_avatar, symbol, change_address, results[0].change)

tx = await wallet.sign(tx)
Expand Down
2 changes: 1 addition & 1 deletion examples/mit_transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let results = await Promise.all([
type: "mit"
})
])
let tx = await Metaverse.transaction_builder.transferMIT(results[0].utxo.concat(results[1]), "nova", recipient_address, recipient_avatar, "MIT_SUPERNOVA", change_address, results[0].change))
let tx = await Metaverse.transaction_builder.transferMIT(results[0].utxo.concat(results[1]), "nova", recipient_address, recipient_avatar, "MIT_SUPERNOVA", change_address, results[0].change)
tx = await wallet.sign(tx))
tx = await tx.encode())
tx = await blockchain.transaction.broadcast(tx.toString('hex')))
Expand Down
Loading