Last active
November 24, 2016 08:30
-
-
Save vkobel/7d6992a2e3e5d1afa77f384db8b11529 to your computer and use it in GitHub Desktop.
Ethereum simple contract storage using logs (events) and query it
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
var newWall = eth.contract([{"constant":false,"inputs":[{"name":"message","type":"string"}],"name":"publish","outputs":[],"payable":false,"type":"function"},{"payable":false,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"message","type":"string"},{"indexed":false,"name":"addr","type":"address"}],"name":"LogMessage","type":"event"}]).at("0xfFf537A2E812B0Cd738bf913a476FE45Bd5484bE"); | |
var msgEvt = newWall.LogMessage({}, {fromBlock: 0, toBlock: 'latest'}); | |
function getLogs(){ | |
msgEvt.get(function(err, logs){ | |
for(var k in logs){ | |
console.log(logs[k].args.message); | |
} | |
}) | |
} |
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
pragma solidity ^0.4.6; | |
contract NewWall { | |
event LogMessage(string message, address addr); | |
function publish(string message) { | |
if (msg.value > 0) throw; | |
LogMessage(message, msg.sender); | |
} | |
function () { throw; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment