The Information Disorder In Us

When it comes to AR filters and beauty algorithms, it’s important we draw the line between fun and dangerous. The question is “where?”.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Deploying a smart contract to Ethereum

Never before in history has a technology existed where anyone from anywhere can publicly deploy code that will immediately and indefinitely run on tens of thousands of nodes simultaneously and deterministically. Further, thanks to cryptography and cryptoeconomics, this technology is ownerless, trustless, and incentivized to continue. Once a contract is deployed, it is effectively autonomous, eternal, and controlled only by the laws of machines.

Let’s make our mark on the blockchain.

Here is a Simple contract that holds a public count:

The count is initialized in the constructor Simple().

This produces a big chunk of bytecode:

Let’s deploy this bytecode to the testnet:

Also, you’ll need an arguments.js file to pass a number into the constructor:

The output of the deploy looks like this:

At the price of 22gwei, it looks like it cost a dollar to deploy.

Let’s poke around on this contract and see what shakes loose. We’ll want to craft up a few scripts so we aren’t fumbling around on the command line:

Neat, so our current count is 253 and that’s what we deployed the contract with.

This was a read-only action, we didn’t change the state of the contract so reading the count is free for anyone to do as long as they are connected to the Ethereum blockchain.

Let’s run the add() function on the contract to actually change the state.

Now let’s do another getCount() and see what the state of the contract is:

According to Etherscan, to add 1 to that uint it costs about $0.17. That might seem kind of expensive, but what’s actually going on there?

Well, we broadcast to the network that we want to make a transaction, some lucky miner is able to find the correct nonce through brute force cpu power, mines the block containing our transaction and others, broadcasts that to the rest of the network, and then every miner in the world runs our transaction against their version of our contract and gets the same result. We could then ask any of them what our count is and it would be the same. Even as banks, businesses, and governments rise and fall, our count stays exactly where it’s instructed to stay. That is pretty freakin’ awesome.

Let’s lower what we are willing to pay by 1⁄10:

Now let’s run the same transaction again:

Checking on the count now, we see:

Last time it took about 25 seconds to go through. This time it took 55 seconds but the cost was $0.017 or so. This is because the miners are not only incentivized by block mining rewards but also the gas used to run the transactions. It’s up to them to determine which transactions are worth mining. We can trade cost for speed depending on our needs.

We should also touch on security and bugs. This contract is public, so anyone can run the add function and anyone can see the current count. That’s fine for now, but what if there were 100 million USD at stake… yikes! This makes the job of contract developers extremely difficult because everything you do is at the mercy of every bad actor for the rest of time. Every contract interaction is deterministic; we can determine for sure what will happen given a state and an action, but just like a move in chess, predicting every single possible outcome on a chess board is also relatively difficult.

So what happens if we run add() one more time? Assuming no one else has already hit our contract, the count will go up just like before and we should see 256 right? Let’s try it:

Checking on the count now, we see:

Add a comment

Related posts:

How Your Workspace Is Stopping You From Being Productive?

Last year has been hard for all of us and with our life shifting from offices to homes it has become harder. Many people find that they have adjusted to their new lives and for some, it is still…