You are on page 1of 2

1.

Setup dev environment


$ sudo npm install -g truffle
$ sudo npm install -g ganache-cli
$sudo npm install -g create-react-app

Step 1: Create Truffle Project


1.1
Create a dev folder FirstDapp and move into it
$ mkdir FirstDapp
$ cd FirstDapp

1.2 Initialise truffle


$ truffle unbox react

1.3 Launch personal blockchain using Ganache in a newtab

$ ganache-cli -m "thing vanish tomorrow jewel level cool need dust animal patch
pact very"

Step 2: Writing a minimal smart contract and configuring the contract

2.1 SimpleStorage.sol contract in the contracts/ directory we will modify that


contract to take strings.

pragma solidity >=0.4.21 <0.7.0;

contract SimpleStorage {
uint storedData;

function set(uint x) public {


storedData = x;
}

function get() public view returns (uint) {


return storedData;
}
}

2.2 To tell truffle where our personal blockchain Ganache is running edit truffle-
config.js with

const path = require("path");


module.exports = {
contracts_build_directory: path.join(__dirname, "client/src/contracts"),
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
}
}
};

Step 3: Compiling and migrating smart contract


3.1 Compile the smart contract

$truffle compile

3.2 Migrate (deploy) them to our Ganache


Create a new file named 2_deploy_contracts.js in the migrations/directory with
below content.

var SimpleStorage = artifacts.require("./SimpleStorage.sol");

module.exports = function(deployer) {
deployer.deploy(SimpleStorage);
};

3.3 Run migation


$truffle migrate

4.npm run start

/*
If you got any error like SimpleStorage.json file notfound
1. goto client/src/
execute command
$ln -s ../../build/contracts/
*/

You might also like