This video is available to students only

Buying An Image -- Sending Transactions

We can read an image, so now let's color each pixel on the blockchain.

What we're going to do is iterate over each pixel and send a transaction for each pixel we want to color. Of course, this can be a lot of transactions if the image is large. But the idea is that someone is purchasing a scarce pixel, for a long period of time, so it's not that big of a deal if it takes a while to buy the whole image.

Connecting to Web3#

The first thing we need to do is connect to our web3 node:

Here I'm using the HttpProvider, but it's worth looking into the IpcProvider, too.

Getting a handle to the contract#

Next we need a handle to our contract. We do this, like we have before, by loading the ABI and looking up the contract's deployed address.

Because we're sending transactions, we'll also need the sending account address. Normally, you'd configure this as an environment variable or command-line argument, but we can hardcode it for now.

Now that we have the contract, when we loop over each pixel, instead of logging it, we want to call the colorPixel method on the contract to send a transaction: