February 5, 2026

How to test a smart contract using Remix ide – Pradeep

How to test a smart contract using Remix ide – Pradeep

How to test a smart contract using Remix ide – Pradeep

How to test a smart contract using Remix ide – Pradeep

How to test a smart contract using Remix ide

In this article we’ll look at a “Fund proposal” (for demo only) smart contract which can be used to raise funds for proposals.

User roles

The 3 roles played are

  1. Organiser — An account used to create the fund raising smart contract
  2. Proposer- An account used to create a proposal
  3. Donor- An account used to donate ether for a proposal

There can be multiple proposals and multiple donors for each proposal.

For simplicity we’ll demo 1 proposal and 1 donor.

Smart contract

The FundProposal smart contract has the below functions

  1. registerProposal — To register a proposal
  2. registerDonor —Donor registers interest in a proposal
  3. receive- Donor sends ether via this smart contract to the proposer.

Smart code code : https://github.com/gogit/remix-smart-contract/blob/master/FundProposal.sol

The Remix ide will be used for compiling, deploying and testing the smart contract.

Remix ide

Remix ide is a concise and seemingly complete environment to test your smart contract. It provides code completion, compilation, deployment, test function calls etc via plugins.

Installing and Running Remix

git clone https://github.com/ethereum/remix-ide.git
cd remix-ide
npm install
npm start
open http://127.0.0.1:8080 in your browser.

Steps

  1. Create the smart contract
  2. Compile it
  3. Deploy it
  4. Create a proposal
  5. Look at the transactions so far
  6. Register interest for donating funds
  7. Donate funds
  8. Check funds in accounts

Create the smart contract

Click on the + sign and create a new file called FundProposal.sol. Copy the code from https://raw.githubusercontent.com/gogit/remix-smart-contract/master/FundProposal.sol and paste

Compile it

Click on compile to compile the smart contract

Deploy the smart contract

Deploy the smart contract using the first account in the list. After the deployment you’ll see a small decrement in the ether allocated to the first account.

Create a proposal

Use the second account (from the dropdown) to create a proposal using the function “registerProposal”. Once again the account loses a small amount of ether after the transaction.

Look at the transactions so far

Click on transactions recorded and save transactions to see the transaction records. You can also see the accounts involved in the transactions.

Copy the value associated with account[1] (the Proposer 0x147…). You’ll need the proposers address to register as a donor (for this demo).

Register interest for donating funds

Select the 3rd account from the dropdown and use the Proposer address to register as a donor. The account again loses a small amount of ether for this transaction.

Donate funds

FundProposal smart contract has been created using account 1. A proposal has been created using account 2 and a donor registered for this proposal using account 3.

The donor can now send ether to the smart contract that is transferred to the proposal/proposer

  1. Send 30 ether
  2. Send 40 ether

Select account 3, enter the value and scroll all the way down and click on transact

Check funds in accounts

Account 3 (Donor) has transferred 70 ether to account 2 (Proposer)

We have looked at the process involved in creating a smart contract and testing it.

There are loads of gotchas and magic keywords that drive behavior. The links below should be useful

https://github.com/ethereum/

Published at Thu, 06 Feb 2020 14:22:49 +0000

{flickr|100|campaign}

Previous Article

How to test a smart contract using Remix ide – Pradeep

Next Article

How to test a smart contract using Remix ide – Pradeep

You might be interested in …