index.js
var web3 = new Web3(Web3.givenProvider);
var instance;
var user;
var contractAddress = "0x13340FC39784874c1F3916204FB67AE306B71327";
$(document).ready(function() {
window.ethereum.enable().then(function(accounts){
instance = new web3.eth.Contract(abi, contractAddress, {from: accounts[0]})
user = accounts[0];
console.log(instance);
instance.events.Birth().on('data', function(event) {
console.log(event);
let owner = event.returnValues.owner;
let kittenId = event.returnValues.kittenId;
let mumId = event.returnValues.mumId;
let dadId = event.returnValues.dadId;
let genes = event.returnValues.genes;
$("#kittyCreation").css("display", "block");
$("#kittyCreation").text("owner:" + owner
+" kittyId:" + kittenId
+" mumId:" + mumId
+" dadId:" + dadId
+" genes:" + genes)
})
.on("error", console.error);
})
})
function createKitten() {
var dnaStr = getDna();
instance.methods.createKittyGen0(dnaStr).send({}, function(error, txHash){
if (error)
console.log(error);
else
console.log(txHash);
})
}