Ethereum Mastery: 5 essential web3 programming techniques

Clause
Clause
Published in
2 min readFeb 6, 2018

At Clause Inc. we are building a platform for smart legal contracts that targets all the major distributed ledger technologies, including the Ethereum blockchain.

In this article we look at five basic verbs that can be applied to Ethereum Smart Contracts: Connect, Compile, Deploy, Query and Modify.

During the course of our investigations and development we’ve noticed that samples and documentation for Ethereum are not always up to date, particularly for the web3 1.x library used to programmatically access an Ethereum node, and using the latest JavaScript specifications. We’ve therefore decided to share the fruits of our research with the wider community; out of alturism, but also because we’d love to get your feedback and corrections.

Viewing a test account’s transactions using Etherscan

In this first post we are publishing explanatory web3 1.0.x code to:

1. Connect to a local or remote Ethereum node using RPC and the web3 library

2. Compile a Solidity smart contract from source

3. Deploy the compiled contract, signing the deploy transaction using a private key

4. Query the state of a smart contract by calling read-only methods

5. Modify the state of the smart contract by submitting a transaction signed using a private key

For our purposes it is necessary to be able to automate all of these steps without manual human interaction, so the code shows how to programmatically sign transactions using a private key.

Output from compiling, deploying and executing a smart contract

All the usual disclaimers apply: this is test code and has not been deployed to the Ethereum mainnet, or used in production. Use it at your own risk! Please don’t hesitate to file issues on the GitHub repository or post comments.

Please refer to the README.md for detailed instructions on how to install and run the code. The source code has been heavily commented to help you get up to speed.

--

--

Clause
Clause
Editor for

The future of legal contracting. This blog has been relocated to https://blog.clause.io/. Our Medium feed will no longer be updated.