Using Ethermint with Truffle

Billy Rennekamp
Interchain Ecosystem Blog
4 min readSep 18, 2017

--

This month I participated in the Cosmos Hackatom Hackathon. Cosmos is a company out of Tendermint who has created a protocol for making transactions on blockchains without incurring the huge costs of traditional mining (in electricity or miner fees) by using another method for consensus (Byzantine Fault Tolerance which is apparently vulnerable to untrustworthy nodes but whose achilles heel can be solved with Proof of Stake). One example of this Application BlockChain Interface (ABCI) is the creation of Ethermint, a Tendermint powered version of the Ethereum Blockchain.

The project I worked on for the hackathon needs to take a series of moves from the board game Reversi and play the game inside of an Ethereum Contract in order to confirm the game is valid. If the game is valid and the endgame forms a symmetrical board the user receives a reward in an ERC20 Token (Reversi-Search as Proof-Of-Work™). Even though the game is relatively simple to program, it includes lots of loops and arrays which are VERY expensive on the EVM, so naturally Ethermint would be a huge boon to the project (If you’re interested in how to reduce costs by avoiding arrays check out this technique and if you’re interested in the project check it out at clovers.networkUpdate: We won a prize!).

Installation

Install instructions are found on the github repo, it says you can download a binary from here but there was no Mac version listed so I followed the Install From Source instructions. First you need get Go, they recommended using gvm—which was great because it handles aliases and I seem to always have trouble with aliases — remembering if I need to update $PATH in the terminal, in .bash_profile, in .baschrc, restart the terminal, flush something??

The next parts were pretty straightforward and went off without a hitch following their instructions to first install Ethermint, then Tendermint, then initialize them with default files and finally run the damn thing. This is where I started having trouble, I got both programs to run in different terminal windows following their recommended start commands:

tendermint --home ~/.ethermint/tendermint node

which spits out red errors until you switch to a new terminal window and do:

ethermint --datadir ~/.ethermint --rpc --rpcaddr=0.0.0.0 --ws --wsaddr=0.0.0.0 --rpcapi eth,net,web3,personal,admin

The results look pretty similar to the few times I’d tried running Geth on my machine. The instructions said I could use Truffle without any extra arguments so I gave it a shot—no go.

truffle compile
truffle migrate
...Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: authentication needed: password or unlock

Unlocking

So I guess I need to unlock Ethermint first, I wasn’t even sure what my wallet address was so I looked into the ~/.ethermint directory I’d installed earlier and found a keystore that Itook to myetherwallet.com. I realized that since the keystore was in a hidden folder it wouldn’t be present in the Finder dialogue but googled a helpful shortcut of Command-Shift-Period to make Finder show hidden files. I uploaded the keystore, unlocked it with 1234 and found my address. Now equipped I went back and tried:

ethermint --datadir ~/.ethermint --rpc --rpcaddr=0.0.0.0 --ws --wsaddr=0.0.0.0 --rpcapi eth,net,web3,personal,admin --unlock 0xMY4W350M3W411374DDR355

but got Fatal: Error starting protocol stack: resource temporarily unavailable. I’ve had trouble with geth after stopping and starting, realizing it actually stayed alive somewhere in the background 👻, so I tried to find a kill command.killall -9 ethermint seemed to do the trick 💀. After starting Ethermint again the red errors inside of Tendermint didn’t stop and Ethermint kept repeating Waiting for tendermint endpoint to start err=”Post http://localhost:46657/status: dial tcp [::1]:46657: getsockopt: connection refused”. I force stopped Tendermint (Control-C) then tried it again but realized it too lived on somewhere panic: Panicked on a Sanity Check: Error initializing DB: resource temporarily unavailable killed it 🔪killall -9 tendermint and tried it all again:

tendermint --home ~/.ethermint/tendermint nodeethermint --datadir ~/.ethermint --rpc --rpcaddr=0.0.0.0 --ws --wsaddr=0.0.0.0 --rpcapi eth,net,web3,personal,admin  – unlock 0xMY4W350M3W411374DDR355

still got over and over again:

INFO [09-16|23:13:26] Waiting for tendermint endpoint to start err="Post http://localhost:46657/status: dial tcp [::1]:46657: getsockopt: connection refused"

Assistance

As a last resort I went over to cosmos.rocket.chat where Cosmos employees let you bother them and got ahold of very helpful Adrian Brink who told me I just type the password right into the oncoming mess of waiting for tendermint and duh it worked, all errors and red text stopped. Afterwards I ran truffle compile && truffle migrate and I got a successful deploy 🎉

Now I’m able to get super fast confirmations at tiny gas prices using my dApp with Mist. I’m running my node locally so I’m the only user right now, but once Ethermint’s public test net is ready (October?) I could deploy there and launch the app publicly. Seem’s all that’s left now is getting Ethermint to play nice with MetaMask 🦊

--

--