Write Your First Smart Contract
First step of being a blockchain developer
In Remix, create a new file with name icon in browser section under FILE EXPLORERS section and start writing the code as mentioned below.
Quote.sol
by clicking ➕
pragma solidity >=0.5.0<0.6.0;
Make sure the solidity version declared in the contract matches your compiler version
contract Quote { }
quote
is used to store the current quote in our smart contractowner
is used to store the owner of the current quote
string public quote;
address public owner;
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.function setQuote(string memory newQuote) public {
quote = newQuote;
owner = msg.sender;
}
Returns the current quote and the current owner of the quote.
function getQuote() view public returns(string memory currentQuote, address currentOwner) {
currentQuote = quote;
currentOwner = owner;
}
Quote.sol
pragma solidity >=0.5.0 <0.6.0;
contract Quote{
string public quote;
address public owner;
function setQuote(string memory newQuote) public {
quote = newQuote;
owner = msg.sender;
}
function getQuote() view public returns(string memory currentQuote, address currentOwner) {
currentQuote = quote;
currentOwner = owner;
}
}
This tutorial is deployed on Kovan TestNet at address 0xa67767B5ed6Fa6Fc19baBD4F18ffe72EAbC85FdA
Last modified 2yr ago