Deploying contracts using geth
After writing your smart contract, it is time to deploy it in Ethereum. In this recipe, you will learn about deploying your smart contract and testing it to ensure that it works as intended.
Getting ready
You will need a working installation of the solc
compiler to compile your contract and geth
to deploy it. We will be using the geth
JavaScript console to run the deployment and transaction scripts.
How to do it...
- Here is our simple smart contract example:
pragma solidity ^0.4.21; contract HelloWorld { string public greeting = "Hello World"; function changeGreeting(string _newGreeting) public { greeting = _newGreeting; } }
- Use
solc
or other alternatives to compile the contract into ABI and bytecode:
$ solc --optimize --bin --abi HelloWorld.sol
- Start the
geth
node with the web3 console:
$ geth console 2>> ./geth.log
- Make sure that you have enough Ether for deployment. If you are using a private network, make sure to start mining before performing...