DEV Community

Cover image for Create Your First Smart Contract in Solidity and Upload it to Kalp Instant Deployer.
Asjad Ahmed Khan for Kalp Studio

Posted on

Create Your First Smart Contract in Solidity and Upload it to Kalp Instant Deployer.

Introduction

Smart contracts are self-executing programmes where the terms of the agreement are written into code. Solidity is the most widely used language to write these contracts on Ethereum and other EVM-compatible blockchains. Deploying a smart contract used to be a challenging task involving complex tools like Truffle and command-line interfaces, but Kalp Studio makes the deployment process much more manageable. In this tutorial, we will walk through creating your first smart contract in Solidity and deploying it using the Kalp Instant Deployer on the Holesky test network.

Prerequisites

Before you begin, here’s the list of items that you would need:

  • Basic Understanding of Solidity: Don’t worry if you’re completely new; the tutorial will cover basic concepts.
  • Kalp Studio Account: Kalp Studio is a decentralized infrastructure platform designed to build, manage, and scale blockchain applications and networks. Sign-up here to start using Kalp Studio.
  • A Custodial Wallet on Ethereum Blockchain and on Holesky Network: For this tutorial, we will use Kalp Studio’s Custodial Wallet operating on Ethereum Blockchain and the Holesky network. To follow the steps on how to create the required Custodial Wallet, please go through our first tutorial before proceeding further: Creating your Custodial Ethereum Wallet on Holsekey Network, using Kalp Studio

Now that our basic setup is ready, it’s time to create our first Smart Contract in Solidity.

Creating the Smart Contract

You will need a Solidity development environment to write and test your contract. For this tutorial, we will use the Remix IDE (Feel free to use the IDE of your choice).

  • Create a new .sol file in your editor and type the following code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MyFirstContract {
    string public message;

    // Constructor to initialize the contract with a message
    constructor(string memory _message) {
        message = _message;
    }

    // Function to update the message
    function updateMessage(string memory _newMessage) public {
        message = _newMessage;
    }

    // Function to retrieve the current message
    function getMessage() public view returns (string memory) {
        return message;
    }
}
Enter fullscreen mode Exit fullscreen mode
  • Save the file within your desired location.

Explanation of the Contract:

  • pragma solidity ^0.8.0;: Specifies the version of Solidity to be used.
  • string public message;: Declares a state variable message that stores a string. The public keyword makes it accessible externally.
  • constructor: A function that is executed when the contract is deployed. It initializes the message with the provided string.
  • updateMessage: This function allows users to update the stored message.
  • getMessage: This function returns the current message. Since it is marked as view, it doesn’t cost gas to call this function.

Compiling the Smart Contract

After writing the contract, compile it in Remix:

  • Click on the “Solidity Compiler” icon in the sidebar.
  • Ensure the version is set to 0.8.0 or the version of Solidity you’re using.
  • Click on the Compile MyFirstContract.sol button.

Remix IDE

You should see a green checkmark next to the compiler button indicating a successful compilation if everything is correct.

Now that we have successfully created and compiled our smart contract, it’s time to test the power of Kalp Studio and deploy it using the Kalp Instant Deployer.

(Feel free to use the smart contract of your choice. The smart contract used here is solely for the tutorial’s purpose)

Deploying the Smart Contract on Kalp Instant Deployer

Before diving further, please ensure that you have connected to Custodial Wallet. Refer to the tutorial here, for more details about creating and connecting the wallet.

  • On your Kalp Studio’s Dashboard, navigate to Kalp Instant Deployer card and click Explore.

Kalp Instant Deployer Navigation

  • Now, you’ll be redirected to the Smart Contracts page where the list of your deployed smart contracts will be shown.
  • Since we are deploying a new smart contract, let’s click on the + Deploy New button.

Smart Contract List

  • After clicking the + Deploy New button, you’ll be redirected to the Create Smart Contract form. Fill in the details and click Continue.

Smart Contract Form

(The Name can be of your choice. In the Category section, choose the desired category from the dropdown, and you can also provide the description of your choice.)

  • Next, you need to upload your smart contract which we saved as a .sol file in the beginning of the tutorial, and then click on Continue.

Uploading Smart Contract

  • Check all your details, and once it is finalised, click Continue.

Uploaded Smart Contract

  • Wait for a few seconds, and if you followed the above steps correctly, you would have successfully deployed your smart contract.

Smart Contract List

You can view your deployed smart contract here: Uploaded Smart Contract

Notice that on the above page, you can find the essential details about your deployed smart contract, like ID, Name, Category, Network, Blockchain and so much more.

Conclusion

Congratulations! You’ve just written your first smart contract in Solidity, compiled it in Remix, and deployed it using Kalp Instant Deployer. This simple contract demonstrates the basic principles of blockchain development, and now you can build more complex applications by extending this foundation.

With Kalp Studio, deployment has never been easier, removing much of the complexity traditionally involved in smart contract deployment. Keep experimenting, and soon you’ll be building robust decentralized applications!

What's Next?

In the upcoming tutorials, we will see how we can generate end-points from our deployed smart contract using Kalp Studio’s API Gateway. Stay tuned!

To learn more about Kalp Studio, explore our documentation, feel free to post your queries, and follow us for updates on our Discord server.

Top comments (0)