This is a tutorial on how to create a HelloWorld smart contract using Solidity.
- Node.js installed on your computer
- Truffle framework installed
truffle init
Create a new file in the contracts directory called HelloWorld.sol.
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.21 <0.8.22;
contract HelloWorld {
string public message;
constructor() {
message = "Hello, World!";
}
function getMessage() public view returns(string memory){
return (message);
}
}
truffle compile
truffle migrate
const HelloWorld = artifacts.require("HelloWorld");
const contract = await HelloWorld.deployed();
const message = await contract.getMessage();
console.log(message); // "Hello, World!"
You have now successfully created, compiled, deployed, and interacted with a HelloWorld smart contract.