Hands-On Blockchain Development in 7 Days by Will Button
Author:Will Button
Language: eng
Format: epub
Tags: COM018000 - COMPUTERS / Data Processing, COM083000 - COMPUTERS / Security / Cryptography, COM062000 - COMPUTERS / Data Modeling and Design
Publisher: Packt Publishing
Published: 2019-03-15T04:27:58+00:00
Then we're going to use async and await to get the deployed version of our contract from the Ethereum network. So, let me break a async and await down for you in case you haven't seen that before. Let's say we had a line of JavaScript: it's going to use the artifact we imported representing our contract to get the actual contract instance deployed on the Ethereum network, but the way JavaScript works once we call this function means that it thinks it's done and it moves on from here: it's asynchronous. So, even though we called the deployed function and it hasn't returned a value, JavaScript moved on anyway. The gaming variable is actually undefined until this call completes, which causes a lot of headaches as you try to figure out why this variable sometimes has a value, and sometimes doesn't:
gaming = Gaming.deployed()
const fundGame = gaming.fundGame()
So, to avoid that pain we use async and await. The way it works is we declare this anonymous function here using the async keyword, then inside the function anytime we have a function or call that we need to wait on we use the await keyword. Now, there's a lot more going on under the hood than that, but that's the bare minimum you need to know to understand this. Instead of async and await, some other patterns you might see include callbacks and promises.
And now we've got one more variable declared, which is a constant called fundGame. This function lets me send some initial Ethereum to the contract, so that as we start testing our contract has some funds to pay out any winners. Without this Ethereum, any test that results in a winning scenario would fail because the contract would have insufficient funds to cover the payout. And take a look at this: it's also using the await keyword, because once we call this function it doesn't mean the execution is complete. We need to wait for that block to be mined before the operation is considered a success:
const fundGame = await gaming.fundGame({from: owner, value: web3.utils.toWei('10', 'ether')})
})
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Cryptography | Encryption |
Hacking | Network Security |
Privacy & Online Safety | Security Certifications |
Viruses |
Effective Threat Investigation for SOC Analysts by Yahia Mostafa;(6497)
Practical Memory Forensics by Svetlana Ostrovskaya & Oleg Skulkin(6216)
Machine Learning Security Principles by John Paul Mueller(6181)
Attacking and Exploiting Modern Web Applications by Simone Onofri & Donato Onofri(5851)
Operationalizing Threat Intelligence by Kyle Wilhoit & Joseph Opacki(5818)
Solidity Programming Essentials by Ritesh Modi(3991)
Microsoft 365 Security, Compliance, and Identity Administration by Peter Rising(3633)
Operationalizing Threat Intelligence by Joseph Opacki Kyle Wilhoit(3360)
Future Crimes by Marc Goodman(3345)
Mastering Python for Networking and Security by José Manuel Ortega(3344)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3327)
Blockchain Basics by Daniel Drescher(3292)
Learn Computer Forensics - Second Edition by William Oettinger(3129)
Mobile App Reverse Engineering by Abhinav Mishra(2879)
Mastering Bitcoin: Programming the Open Blockchain by Andreas M. Antonopoulos(2867)
Incident Response with Threat Intelligence by Roberto MartÃnez(2847)
The Code Book by Simon Singh(2822)
From CIA to APT: An Introduction to Cyber Security by Edward G. Amoroso & Matthew E. Amoroso(2776)
Building a Next-Gen SOC with IBM QRadar: Accelerate your security operations and detect cyber threats effectively by Ashish M Kothekar(2673)
