We’ve created a functioning Agoric demo that you can work within, showcasing our electronic rights technology. The demo takes the form of buying and selling pixels, inspired by Reddit’s r/Place experiment. Yes, in our demo you’re just buying and selling pixels, but you can also easily imagine that each pixel is an abstract of some greater property, such as an electronic ticket, rights to digital art, or some other digital asset.
What you’re experiencing is very much a work-in-progress. We are inviting you to #buidl on our testnet as we build it. This requires a provisioning code. If you have it, proceed with the instructions below, and if you don’t, get in touch.
Let’s get started
Requirements
You can run the Pixel Demo right from your browser. There are different scenarios of how you can run the Pixel Demo, but with docker, you will need to install:
Next, run:
git clone [email protected]:Agoric/cosmic-swingset.git
cd cosmic-swingset
SOLO_NAME=han ./docker/ag-setup-solo --pull
This command will prompt you for the testnet provisioning code. Enter it and then connect to http://localhost:8000
The 5 minute Demo: Part 1: Coloring the Pixel
1.1: Access Gallery
To access the gallery, type
home.gallery
in the REPL.home.gallery
is a remote object, we call a presence.It actually lives in another environment, what we call a vat.
Instead of obj.foo(), you can talk asynchronously to local and remote objects in exactly the same way in two ways:
E(obj).foo() obj~.foo() — new syntax — ‘wavy dot’ (syntactic sugar)
This syntax means:
“deliver the message foo() to the actual object asynchronously, in its own turn, wherever and whenever it is, even if it is local.”
1.2: Get a free pixel
Let’s use this to call
tapFaucet()
px = home.gallery~.tapFaucet()
This returns a pixel and saves it under
px
. You will see unresolved Promise, until your pixel is returned from the testnet:The pixel that you receive is actually in the form of an ERTP payment. ERTP (Electronic Rights Transfer Protocol) is our smart contract framework for handling transferable objects. Payments have a few functions.
1.3: Get pixel information
Call
px~.getBalance()
on our payment to see which pixel we received.
Here, we received pixel x:2 y:2 on the grid (3 across, 3 down).
1.4: Get use object
To color the pixel, we need to get the use object from the payment. Run:
use = px~.getUse()
(You can think of the use object as a regular JavaScript object that just happens to be associated with an ERTP payment)
Now we can use the use object to color our x:2, y:2 pixel:
1.5: Color our pixel
Let’s make it pink:
use~.changeColorAll('#FF69B4')
Success! Pretty in pink.
PART 2: Selling my pixel
2.1: Now I need to sell my pixel. Again, let’s get the pixel location, but this time, save to amt:
amt = px~.getBalance();
2.2: Now I need to get the exact price of this pixel (hopefully it’s worth more now it’s pink):
amt.then(a => home.gallery~.pricePixelAssetDesc(a));
2.3: 5 is the price. Let’s start the sales process. Here I tell the gallery that I have a pixel to sell:
hostInvite = home.gallery~.sellToGallery(amt);
2.4: I received the “invite”, which I can redeem for a seat. Think of it like showing your ID before being allowed to start selling.
seat = hostInvite~.host~.redeem(hostInvite~.inviteP);
2.5: From my seat, I now get the offer for this pixel.
offered = seat~.offer(px);
2.6: Get assays:
assays = home.gallery~.getAssays();
2.7: Get an empty pixel purse from the assay:
pxPurse = assays~.pixelAssay~.makeEmptyPurse();
2.8: Your
home.purse
is an empty purse for receiving dust
. If you wanted to make another one, then run:dustPurse = assays~.dustAssay~.makeEmptyPurse();
2.9: Setup the agreement and make the transaction:
collected = Promise.all([offered, dustPurse, pxPurse]).then(_ => home.gallery~.collectFromGallery(seat, dustPurse, pxPurse, 'my escrow'));
2.10: Show the final amount in the dustPurse once the transaction is complete:
collected.then(_ => dustPurse~.getBalance());
Your pixel is sold and the transaction is written to the chain. Voila! Yes, the testnet is still rough, but just think of all the things you’ll be able to build in it down the road.
The Agoric testnet material can be found on our GitHub. Remember, you will need a provisioning code during the setup process. If you don’t have one, you can reach out to me directly on Telegram at @tatyana_agoric.
Thanks for reading! You can join the Agoric community on Twitter, Telegram, LinkedIn, and catch us at these upcoming events.