Photo by Cytonn Photography on Unsplash

Solana Development (5): Deploy your First Smart Contract

By Brochain | Solana Development | 25 Apr 2022


In this article, we will walk you through how to deploy a Smart Contract in Solana. In Solana, all Smart Contracts are called On-Chain Program. So, from now-on, we will call it program instead of Smart Contract. We will use Solana’s Hello World as an example on how to deploy. You may find its github here. Below, we will introduce how to deploy this contract on a local cluster. If you are not familiar with how to setup a local cluster, you can take a look of my previous post first.

Installation

Suppose you have already setup your local cluster successfully, next thing you should do is download the hello-world project and its dependencies. To deploy hello-world, you would also need to download npm and node.

$ sudo apt-get update
$ sudo apt-get nodejs npm

After installation, clone the helloworld project and build it

$ git clone https://github.com/solana-labs/example-helloworld.git
$ cd example-helloworld
$ npm install
$ npm run build:program-rust

Deploy the contract

Now, your installation should be done. Let’s spin up a local cluster:

$ solana-test-validator

Now, open a new console, deploy the contract:

$ cd example-helloworld
$ solana program deploy dist/program/helloworld.so
$ npm run start

If you see something like below, congratulations! You have successfully deployed your first smart contract on Solana!

Let's say hello to a Solana account...Connection to cluster established: http://127.0.0.1:8899 { 'feature-set': 1813598585, 'solana-core': '1.8.0' }Using account JC1qGm4wV8LHJwdpNFmG3KKW3uNpuANLecuaP2xiUj7 containing 5.25006476 SOL to pay for feesUsing program AgxCYWW6tJq6eLopHxTy94c6xbkcV4BumjVrAYRw81HaSaying hello to 6YpWGr3xz9zq4h84fsq4dLR97BD5TUFTDij82j1Skjqz6YpWGr3xz9zq4h84fsq4dLR97BD5TUFTDij82j1Skjqz has been greeted 1 time(s)Success

In next post, we will walk through the code of hello-world and see how this magic works. So, stay tuned and see you soon!

How do you rate this article?


15

0

Brochain
Brochain

Web3 Developer. The best way to learn is to share what you learnt.


Solana Development
Solana Development

Welcome to my blog. This blog would be about Solana Development. So, if you are interested to know how to write smart contract, web3 programs in Solana, stay tuned! Cheers!

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.