Subscribe to get access to this video

and the whole library of videos, sample code, and tutorials.

Million Ether Page Essential Smart Contract

Let’s build the essential contract for the Million Ether page. First, let’s make a place for it.

mkdir -p ~/courses/newline-web3/million-ether-page
cd ~/courses/newline-web3/million-ether-page
mkdir contracts
# edit contracts/MillionEtherPage.sol

We’re going to be storing our pixels in a 1000x1000 grid. The zero-zero point is the top left with x increasing to the right, and y increasing towards the bottom.

[slide 1000x1000x grid. Origin incrementing top-left]

Remember that we’re storing each pixel as 3 bytes. The datatype for this in Solidity is bytes3. In our contract, we’ll represent this grid, initially, as a two dimensional array of bytes3.

// MillionEtherPage-001.sol
pragma solidity ^0.4.11;

contract MillionEtherPage {
  bytes3[1000][1000] public pixels;

  function colorPixel(uint x, uint y, bytes3 color) {
    pixels[x][y] = color;
  }
}

This array is going to be stored in our contract’s storage. That is, every node on the Ethereum network will hold a copy of these pixels.

We’ll mark these pixels public which means that Solidity will automatically create a public getter function to read these values.

colorPixel

To set a pixel color, we’ll use the function colorPixel - it accepts an unsigned integer for the x and y location and a bytes3 for the color.

When this function is called, it will update the pixel at the appropriate location.

This contract is simple. We’re storing a million pixels in our contract, with no restriction. This is just the first version. Over the next few videos we’re going to talk about how bid for and buy pixels, how to emit events when pixels change, and how to give refunds when someone is outbid.

 

Subscribe to get the full text of this lesson

and the entire library of videos, sample code, and tutorials.