Smart Contract to change the value/state of a variable on Ethereum Blockchain.
- IntelliJ - install solidity plugin
- Setup truffle - npm install -g truffle
- Ganache CLI Setup - npm install -g ganache-cli
- Truffle hd wallet & dotenv package - npm install -g truffle-hdwallet-provider dotenv --unsafe-perm=true --allow-root
- Install Metamask browser plugin and create account. You'll get 12 word mnemonic. Save it somewhere safe.
- .env file on you local which will contain your private key (# DO NOT SHARE IT ANYWHERE) it should look like : TEST_MNEMONIC=<YOUR_12_WORD_MNEMONIC>
-
Clone project on your local.
-
Start ganache-cli $ganache-cli (for local)
-
Start truffle
- to connect it with local blockchain ganache $truffle migrate (for local)
- to connect it with Ropsten test network $truffle migrate --network ropsten-infura --reset ()
-
start interacting
-
$truffle console
it will open a truffule command line interface to connect with the contract
-
$var contract=await StateChange.deployed();
-
to get the Default value :
$await contract.getValue();
-
Insert a new value
$await contract.setValue("Sachin"); For a GUI interface ,checkout my below code https://github.com/divyanailwal73/StateChangeUI
-
Above UI code is connecting to the same SmartContract which you checkout on your local just now. With the UI code you can learn how to interact with smart contracts via JS :)