Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Ethereum Cookbook

You're reading from   Ethereum Cookbook Over 100 recipes covering Ethereum-based tokens, games, wallets, smart contracts, protocols, and Dapps

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789133998
Length 404 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Manoj P R Manoj P R
Author Profile Icon Manoj P R
Manoj P R
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started 2. Smart Contract Development FREE CHAPTER 3. Interacting with the Contract 4. The Truffle Suite 5. Tokens and ICOs 6. Games and DAOs 7. Advanced Solidity 8. Smart Contract Security 9. Design Decisions 10. Other Protocols and Applications 11. Miscellaneous 12. Other Books You May Enjoy

Installing a solidity compiler

You have multiple options when it comes to compiling smart contracts written in solidity. In this recipe, you will learn about installing a solidity compiler and using it to compile your smart contract.

Getting ready

If you are using macOS, you will need homebrew to install the binary compiler. There are other options, such as using npm or docker, which require Node.js and Docker, respectively, installed on your machine.

How to do it...

  1. If you are in Ubuntu, use ppa to install the compiler by running the following command:
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc
  1. If you are using macOS, install the compiler using brew:
brew update
brew tap ethereum/ethereum
brew install solidity
  1. Verify the installation with the following command:
solc --version
  1. Use this command to compile a contract and print the binary:
solc --bin SampleContract.sol
  1. You want to get some of the more advanced output from solc:
solc -o outDirectory --bin --ast --asm --abi --opcodes SampleContract.sol

We can configure it using these provided flags:

  • --ast: Abstracts the syntax trees of source files
  • --asm: EVM assembly of the contracts
  • --abi: ABI specification of the contracts
  • --opcodes: Opcodes of the contracts

You can get the complete list of operations supported by the solc compiler by running solc --help.

There's more...

There is also a JavaScript-based solidity compiler available for you to use. You can install SolcJS using npm. The solc-js project is derived from the C++ solc project and can be used in JavaScript projects directly:

npm install -g solc

To see all the supported features, run the following command:

solcjs --help
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime