Write Your First Smart Contract
First step of being a blockchain developer
​Remix is a powerful, open source tool that helps you write Solidity contracts straight from the browser. Remix also supports testing, debugging and deploying of smart contracts and much more. It is recommended to use Remix to create and deploy smart contracts quickly.
In Remix, create a new file with name Quote.sol by clicking
βž•
icon in browser section under FILE EXPLORERS section and start writing the code as mentioned below.

Mention Compiler Version

1
pragma solidity >=0.5.0<0.6.0;
Copied!
Make sure the solidity version declared in the contract matches your compiler version

Declare Contract Statement

1
contract Quote { }
Copied!

Add Public Variables

quote is used to store the current quote in our smart contract
owner is used to store the owner of the current quote
1
string public quote;
2
address public owner;
Copied!

Setter Function

Updates the current quote and the current owner of the quote. Here msg.sender is used to extract the user address who signed the transaction.
1
function setQuote(string memory newQuote) public {
2
quote = newQuote;
3
owner = msg.sender;
4
}
Copied!

Getter Function

Returns the current quote and the current owner of the quote.
1
function getQuote() view public returns(string memory currentQuote, address currentOwner) {
2
currentQuote = quote;
3
currentOwner = owner;
4
}
Copied!

Complete Code Snippet

Quote.sol
1
pragma solidity >=0.5.0 <0.6.0;
2
​
3
contract Quote{
4
​
5
string public quote;
6
address public owner;
7
​
8
function setQuote(string memory newQuote) public {
9
quote = newQuote;
10
owner = msg.sender;
11
}
12
13
function getQuote() view public returns(string memory currentQuote, address currentOwner) {
14
currentQuote = quote;
15
currentOwner = owner;
16
}
17
}
Copied!
This tutorial is deployed on Kovan TestNet at address 0xa67767B5ed6Fa6Fc19baBD4F18ffe72EAbC85FdA
Last modified 1yr ago
Copy link