Last active
August 2, 2018 11:20
-
-
Save eduardonunesp/95f9b7dacd6458082c6542deb9e225ce to your computer and use it in GitHub Desktop.
Using `loom-umd` on browser, this code works with `truffle-dappchain-example`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="style.css"> | |
<script language="javascript" type="text/javascript" src="https://cdn.rawgit.com/ethereum/web3.js/1.0/dist/web3.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/loom-js@1.15.0/dist/loom.umd.js"></script> | |
</head> | |
<body> | |
<script> | |
window.addEventListener('load', function () { | |
// Make sure to have loomchain running before test | |
this.privateKey = loom.CryptoUtils.generatePrivateKey() | |
this.publicKey = loom.CryptoUtils.publicKeyFromPrivateKey(this.privateKey) | |
this.client = new loom.Client( | |
'default', | |
'ws://127.0.0.1:46657/websocket', | |
'ws://127.0.0.1:9999/queryws', | |
) | |
this.client.on('error', msg => { | |
console.error('Error on connect to client', msg) | |
console.warn('Please verify if loom command is running') | |
}) | |
this.currentUserAddress = loom.LocalAddress.fromPublicKey(this.publicKey).toString() | |
const ABI = [ | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"name": "_value", | |
"type": "uint256" | |
}, | |
{ | |
"indexed": false, | |
"name": "_sender", | |
"type": "address" | |
} | |
], | |
"name": "NewValueSet", | |
"type": "event" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"name": "set", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"name": "setAnotherValue", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "get", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
}, | |
{ | |
"name": "", | |
"type": "address" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
} | |
] | |
// Update this address before test | |
const contractAddress = "0x60ab575af210cc952999976854e938447e919871" | |
this.web3 = new Web3(new loom.LoomProvider(this.client, this.privateKey)) | |
this.simpleStoreInstance = new this.web3.eth.Contract(ABI, contractAddress, { | |
from: this.currentUserAddress | |
}) | |
this.simpleStoreInstance.events.NewValueSet({}, (err, event) => { | |
if (err) console.error('Error on event', err) | |
else { | |
console.log('event', event.returnValues) | |
} | |
}) | |
this.simpleStoreInstance.methods.set(1).send({ | |
from: this.currentUserAddress | |
}) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment