Created
May 30, 2018 07:59
-
-
Save mattkanwisher/334ff4e53e72088c84f35f021e0aa514 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const privateKey = CryptoUtils.generatePrivateKey() | |
const publicKey = CryptoUtils.publicKeyFromPrivateKey(privateKey) | |
const client = getClient(privateKey, publicKey) | |
const from = LocalAddress.fromPublicKey(publicKey).toString() | |
const web3 = new Web3(new LoomProvider(client)) | |
this.user = from | |
const ABI = [{"constant":false,"inputs":[{"name":"_postId","type":"uint256"},{"name":"_text","type":"string"}],"name":"newComment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"posts","outputs":[{"name":"text","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"commentFromAccount","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_text","type":"string"}],"name":"newPost","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"hasPosts","outputs":[{"name":"_hasPosts","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"comments","outputs":[{"name":"text","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"postsFromAccount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"name":"commentsFromPost","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"postId","type":"uint256"},{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"text","type":"string"}],"name":"NewPostAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"postId","type":"uint256"},{"indexed":false,"name":"commentId","type":"uint256"},{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"text","type":"string"}],"name":"NewCommentAdded","type":"event"}] | |
const loomContractAddress = await client.getContractAddressAsync('SimpleSocialNetwork') | |
const contractAddress = CryptoUtils.bytesToHexAddr(loomContractAddress.local.bytes) | |
this._contract = new web3.eth.Contract(ABI, contractAddress, {from}) | |
this.ready = true | |
this._contract.events.NewPostAdded({}, (err, event) => { | |
if (this.onNewPostAdded) { | |
this.onNewPostAdded(event.returnValues) | |
} | |
}) | |
this._contract.events.NewCommentAdded({}, (err, event) => { | |
if (this.onNewCommentAdded) { | |
this.onNewCommentAdded(event.returnValues) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment