Alchemy: Create a Hello World Smart Contract
Learn how to create and deploy a simple hello world smart contract.
Last updated
Was this helpful?
Learn how to create and deploy a simple hello world smart contract.
Last updated
Was this helpful?
Smart contracts are pieces of computer code that are built to run on blockchain networks to facilitate, verify, or negotiate a contract agreement. Smart contracts can only be initiated under certain conditions that users agree on. Currently, smart contracts are mainly used for transactions such as NFT minting, but they can be used for any piece of code, such as a simple tutorial program known as ‘Hello World’ that prints a return string to the screen.
Read below to learn how to create and deploy a simple hello world smart contract.
This tool is available on a Linux or macOS system.
Set up a credentials file for S3FS at ${HOME}/.passwd-s3fs
. You will need to save your Filebase Access and Secret keys to this file and give it owner permissions. You can do so with the following commands:
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
chmod 600 ${HOME}/.passwd-s3fs
You can mount a Filebase IPFS bucket with the command:
s3fs mybucket /path/to/mountpoint -o passwd_file=${HOME}/.passwd-s3fs -o url=https://s3.filebase.com
mybucket: name of your Filebase bucket
/path/to/mountpoint
cd /path/to/mounted/bucket
mkdir helloWorld
cd helloWorld
Select the ‘Create App’ button to get started.
For our example, we called our app ‘hello world’. Set the chain to ‘Ethereum’, and the network to ‘Göerli’.
Start by initiating our project. You should still be in the directory /path/to/mounted/bucket/helloWorld
.
npm init
Here’s how we answered the installation questions:
npm install –save-dev hardhat
npx hardhat
At the prompt, select the ‘Create an empty hardhat.config.js’ option.
mkdir contracts
mkdir scripts
The contracts
folder will be used to store our smart contract, and the scripts
folder will be used to store scripts used to deploy and interact with the smart contract.
Create a new file in the contracts directory and open the file in your preferred IDE such as VsCode. Name this file HelloWorld.sol
. Enter the following content into the file:
dotenv
package with the command:npm install dotenv –save
.env
with the following content:Ethers.js
library with the following command:npm install --save-dev @nomiclabs/hardhat-ethers "ethers@^5.0.0"
hardhat.config.js
file in your code editor.Enter the following content in this file:
Save this file.
npx hardhat compile
To do this, we need to write a script called deploy.js
. Create a new file called deploy.js
in your scripts
directory, then enter the following content in the new file:
Save this file.
deploy.js
script to deploy your smart contract:npx hardhat run scripts/deploy.js --network ropsten
This command will return an output similar to:
Contract deployed to address: 0x9137566f9D8C3722066c3eD2372843b07A6688ae
Save this address value.
Enter the contract address from the previous step in the search bar. The contract address will bring up something like this:
You can click on the transaction details to view more information, such as the transaction’s To and From addresses, the transaction fee, and the gas fee:
ACCESS_KEY_ID is your Filebase Access key, and SECRET_ACCESS_KEY is your Filebase Secret key. For more information on Filebase access keys, see .
Replace ALCHEMY_HTTP_KEY with your Alchemy API key, and replace METAMASK_PRIVATE_KEY with your Metamask private key. For instructions on how to get your Metamask private key, check out .