Create a new Smart Contract

Learn what a Smart Contract is

Alright, let's create our first contract. Head to the Avalanche Starter Kit Codespace and create a new folder called my-contracts in the src folder.

Now in there create a new file called HelloWorld.sol and paste the following contents:

contract HelloWorld {
    function sayHello() public pure returns (string memory) {
        return "Hello World";
    }
}

Now let's deploy the contract:

forge create --rpc-url local-c --private-key $PK src/my-contracts/HelloWorld.sol:HelloWorld --broadcast

If deployed successfully we should see something like this:

[]
Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Deployed to: 0x52C84043CD9c865236f11d9Fc9F56aa003c1f922
Transaction hash: 0x28247e1292e9489c3b51456e2b848eeb6b82ccbcda18836a638f5d81605ac508

This means we have deployed our contract to the address 0x52C84043CD9c865236f11d9Fc9F56aa003c1f922. Using this address we can now call our contract:

cast call --rpc-url local-c 0x52C84043CD9c865236f11d9Fc9F56aa003c1f922 "sayHello()(string)"

Don't forget to replace the contract address with the one your contract was deployed to. The result should look like this:

"Hello World"

Is this guide helpful?

On this page

No Headings
Privacy Policy

We respect your privacy and are committed to protecting your personal data. This privacy policy will inform you about how we look after your personal data and tell you about your privacy rights.

Read full policy