Blockchain & Solidity Program Lab Manual
ISBN 9788119221646

Highlights

Notes

  

Prog. 16:: Ethereum Development program to check balance

Step1:

Step 2: Type the Solidity Program

pragma solidity ^0.4.23;

contract Demo

{

uint public balance;

// Initialize global variables constructor() public

{

balance = 0;

}

// The payable keyword allows this function to accept Ether 
function contribute() public payable

{

// msg.value is the value of Ether sent in a transaction 
balance += msg.value;

}

}

// The contribute function that takes in Ether and updates its balance

Step 3: Add the migration file in migration folder

const Demo = artifacts.require(“Demo”); 
module.exports = function (deployer)

{

deployer.deploy(Demo);

};

Step 4: Update the configuration file truffle-config.js

Step 5: Deploy the solidity program

Step 6: Open the Ganache and see the transaction tab

Select the Second entry 0x2c5a22b93BD20e4cD08e434BD640a2d17447f506

Step 7: Interact with our Demo Contract using Truffle Console

Fire the following command

Check the Balance

Step 8: Lets add some ether into wallet

Copy and Paste any wallet address in Ganache (select 3rd address) and fire the following command

dm.contribute({from:” 0x9C67DEb06b31e82721b968652D4243C90FC2FC06”, value: 10000000000000000000});

1 ether = 108 wei

Check the balance