Useful terms
Gas
This is the cost of running code on the blockchain. Compared to regular where you have all the processing power to yourself, you simply run whatever you want.
The cost of gas is why, as a rule, we all strive to only do the bare minimum amount of processing on the blockchain, and do the rest off chain.
Off chain
When something is being done on regular servers, off the blockchain, and it does not cost gas.
Examples:
- Storing user information in a database
- Uploading a picture to a server
- Responding to a HTTP request
On chain
When something is being processed on the blockchain, and it costs gas.
Examples:
- Transferring cryptocorrency from one address to another
- Creating a bounty (that contains cryptocurrency to be paid out) in the Bounties Network
Smart Contract
Code that is uploaded to the blockchain, and can be executed at the cost of gas. Essentially, all blockchain code.
Web3
This is the Ethereum compatible JavaScript API. It makes it easy to interact with the blockchain right in the browser, or from anywhere you run JavaScript.
Nonce
A random message that cannot be reused. This works as a protection to ensure that a replay attack can't happen.
Rinkeby test net
This is a blockchain used for testing, where you can get free eth to use for gas. It is a great place to test and try out your code, before anything costs real eth on the mainnet.
JavaScript promises
The way we are calling the API in the examples below uses promises. Simply told, a promise is an object that will resolve when the original call has finished. It calls the function given to .then()
, letting you continue your code when it is ready.
Here is the standard example on Mozilla Developer Network for how to create and use a promise. We will only be using promises, not creating them, so the interesting part is line 7 through 9:
var promise1 = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('foo')
}, 300)
})
promise1.then(function(value) {
console.log(value); // expected output: "foo"
})
console.log(promise1) // expected output: [object Promise]
Blockchain development is a big topic, but infographic blog post this blog post highlights how Ethereum works in a simple way. It's a very short read, and worth checking out.
Updated about 6 years ago