contract mortal { /* Define variable owner of the type address*/ address owner; /* this function is executed at initialization and sets the owner of the contract */ function mortal() { owner = msg.sender; } /* Function to recover the funds on the contract */ function kill() { if (msg.sender == owner) suicide(owner); } } contract etherbook is mortal { /* main function */ mapping (address => string) users; event messages(string sender, string message); function etherbook(){ } function register(string Name){ users[msg.sender]=Name; } function sendMessage(string message){ messages(users[msg.sender], message); } } //To compile, paste and run this. var etherbookContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"message","type":"string"}],"name":"sendMessage","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"Name","type":"string"}],"name":"register","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"string"},{"indexed":false,"name":"message","type":"string"}],"name":"messages","type":"event"}]); var etherbook = etherbookContract.new( { from: web3.eth.accounts[0], data: '60606040525b5b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b5b61034d806100426000396000f30060606040526000357c01000000000000000000000000000000000000000000000000000000009004806341c0e1b51461004f578063469c81101461005c578063f2c298be146100ae5761004d565b005b61005a600450610100565b005b6100ac6004803590602001906004018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509050610240565b005b6100fe6004803590602001906004018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509050610194565b005b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561019157600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b80600160005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050908051906020019082805482825590600052602060002090601f0160209004810192821561020f579182015b8281111561020e5782518260005055916020019190600101906101f0565b5b50905061023a919061021c565b80821115610236576000818150600090555060010161021c565b5090565b50505b50565b7f4e952696d62a2836317fb74e2bfa9e297e4319d038c1ec73ab36cdb0eda40e6b600160005060003373ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000508260405180806020018060200183810383528581815481526020019150805480156102e057820191906000526020600020905b8154815290600101906020018083116102c357829003601f168201915b50508381038252848181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f16801561033a5780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a15b5056', gas: 1000000 }, function(e, contract){ if (typeof contract.address != 'undefined') { console.log(e, contract); console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash); }}) //To listen to the chatroom messages, paste this in console and run it. var event = etherbook.messages({}, '', function(error, result){ if (!error) console.log(result.args.sender+":"+result.args.message); }); //To register your name etherbook.register.sendTransaction("your name",{from:eth.accounts[0]}) //To send message etherbook.sendMessage.sendTransaction("hi",{from:eth.accounts[0]})