From f0219b4c86b4b1583fd71536a984cbac03e4b8c3 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Wed, 21 Feb 2018 19:56:49 +0100 Subject: Add pws slide --- slides/pws/script.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 slides/pws/script.js (limited to 'slides/pws/script.js') diff --git a/slides/pws/script.js b/slides/pws/script.js new file mode 100644 index 0000000..3f95d00 --- /dev/null +++ b/slides/pws/script.js @@ -0,0 +1,44 @@ +const web3 = new Web3(new Web3.providers.HttpProvider('http://95.85.1.235:8545')); + +Reveal.initialize({ + history: true, + backgroundTransition: 'slide' +}) + +function addToSlide(data, isHeader) { + const pre = document.createElement('pre'); + if (isHeader) { + pre.classList.add('header'); + } + pre.textContent = data; + + document.querySelector('#blockchain').appendChild(pre); +} + +function compactStr(str) { + return str.substr(0, 10) + '...' + str.substr(str.length - 10); +} + +// addToSlide('012345678901234567890123456789012345678901234567890123456789') + +// Listen for incoming blocks. +const filter = web3.eth.filter('latest'); +filter.watch((err, blockHash) => { + // New block created + if (err) { + throw err; + } + + const block = web3.eth.getBlock(blockHash, true); + console.log(block); + addToSlide(`Block ${block.number}`, true); + + block.transactions.forEach((transaction) => { + if (transaction.from == null || transaction.to == null) { + return; + } + + const humanReadableValue = web3.fromWei(transaction.value, 'ether').toString(); + addToSlide(`${compactStr(transaction.from)} -> ${humanReadableValue} ETHER -> ${compactStr(transaction.to)}`); + }); +}); -- cgit v1.1