Pixelbook setup for truffle

richbodo
3 min readOct 4, 2018

Status: Basic setup and connection between metamask and a dev node works. Connection between truffle test framework and the dev node works. Need to revisit this again to get the drizzle app working.

If you have a recent pixelbook, and you are trying to get set up for smart contract development, then this post may be helpful. Here are my notes on this setup.

Turn on Linux Containers

In settings on your pixelbook, turn on “Linux (Beta)” — it’s at the bottom of the page. Reddit reference:

That should create a virt running a Debian Linux container that has access to a chromium window, which presents as a terminal application.

Crostini gave my container a ton of resources, which is awesome. Modding the resource allocation of new virts and containers is way out of scope for this post, but you would need to learn about Crosh (Ctrl-Alt-t), vmc, lxc and lxd. There are some clues here, here, and here.

Configure your container:

At this point, you will want to copy and paste from the web into your terminal. Fortunately, crostini set up clipboard support for you— you can copy as usual from the web and two-finger click on the trackpad to paste into the terminal.

Here is a gist containing all of the config I needed to get to step 3 in the truffle drizzle tutorial.

Access a local truffle node with Metamask:

The quickest way to develop smart contracts these days is to use truffle and a local eth node of some kind. The easiest dev-node to use is probably ganache, which simulates a local ethereum chain.

You will want to run metamask in chrome, and make sure it works well with other Dapps on mainnet or a testnet before you try to use it to access a local Dapp. That’s out of scope for this post, but get metamask running on a public net first.

Once you have metamask working, you will need to run a local blockchain, fire up a dapp example with truffle against ganache, and connect to your running example.

The hard bit will be finding an IP/Port combination that metamask will actually be able to connect to. I’ll try to post a step by step walkthrough later, but here’s the TL;DR:

  1. Get a truffle example running on your crostini virt using ganache.

2. On your virt, find your IPV4 addy with ```ip address```

3. Now run ganache on that IP rather than the default localhost, (keeping port 8545):

ganache-cli -b 3 -p 8545 -h 100.115.92.198

4. Copy the passphrase words metamask uses as a passphrase

5. In metamask, logout, log back in by importing the accounts with the passphrase words you just copied, and connect to a custom rpc network with your virts IP and port: http://100.115.92.198:8545

6. Configure truffle.js and truffle-config.js for the IP and port that you configured metamask for. Now everything has a consistent config.

7. Running ```truffle test``` should successfully run the tests in your example app.

Those are the key bits. Now you have both metamask and the test infrastructure running. You can write smart contracts, run tests against them with the truffle test infrastructure, and make changes to accounts with metamask.

The front end is still going to need some magic that I will add later.

Other notes:

When you get your dapp running for the first time with npm run start, it will fire up on a weird URL that the virt assigns it — something like:
http://penguin.linux.test:3000/

That will get you to the point where you are asked to log in with metamask, but you can’t connect metamask to that URL — chrome OS and your dns providers, etc. will get in your way.

Metamask will spin forever if it can’t connect. Connect to mainnet to reset the state and then connect to the custom rpc network. Be sure to log out of metamask and re-import with the passphrase your ethereum dev node provides each time you restart your dev node.

I checked out a few resources while figuring this step out:

There is a crostini discord channel: https://discord.gg/abpfxAC

Some more info on accessing your virt that could come in handy:

https://www.reddit.com/r/Crostini/comments/99s3t9/wellknown_ports_are_now_autoforwarded_to_the/

--

--