From Zero to Smart Contract Developer: Stellar
Tags: blockchain, stellar, soroban, sorobanathon
Published: 2023-03-31 11:12:58

In this series of tutorials you'll go through the basics of blockchain technology, send example transactions on Stellar's network and finally write a smart contract for content creators and their viewers. If you're already familiar with classic Stellar assets you can move on to the next post in the series which covers the smart contracts alone.

## What is blockchain?
You can think of blockchain as a decentralized public ledger that records all the transactions in the network. Its general use case is transferring digital money between people and parties. Currently there are lots of blockchains that accomplish this task and some of them additionally support a feature called Smart contracts.

## Smart contracts
Smart contracts are a way to implement an arbitrary user-defined logic that handles transactions on the network. The possibilities are basically infinite but some example use cases that could benefit from incorporating this feature are: your own digital token, a fundraising app or a multiplayer game that distributes collectibles to players.

## Stellar and Soroban
Stellar is a blockchain that was created in 2014. One of the traits that distinguishes it from older Proof-of-Work platforms like Bitcoin is very low transaction fees. Recently the team behind Stellar started developing their own smart contract platform called Soroban that integrates with classic Stellar assets. This tutorial focused on those two technologies.

## Stellar assets
Stellar's native asset is Lumen (XLM). It represents a real world value and can be acquired for example on crypto exchanges. To take part in this tutorial you don't have have to actually spend any money. Stellar hosts two more networks (Test and Futurenet) in addition to its main network, where you can fund your account for free and experiment with all the blockchain's features. We'll use Futurenet from now on as it also supports Soroban. There is a great tool that makes it easy to experiment with Stellar's features called Laboratory and you can find it [here](https://laboratory.stellar.org/#?network=futurenet).

## Creating an account
Stellar uses asymmetric cryptography to enable authentication of transactions. Each account is associated with two keys - public and private. Public key provides you with an identity on the network and private key is needed for signing transactions. Let's start by generating this keypair and funding your account with some starting funds by using [Stellar Lab](https://laboratory.stellar.org/#account-creator?network=futurenet).

![Creating and funding Stellar account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bquyxp9icj5r2ff8v2h9.png)

## Your first transaction
To send your first payment in XLM, you'll have to generate and fund another account first. Note down the keypair you've generated earlier - if you lose it, you'll lose access to the account. Then go to "Build transaction" and fill out the necessary fields:
- Source account
- Click "Fetch next sequence number..." (it needs to be re-fetched after each transaction on an account)
- Operation type: Payment
- Destination
- Asset: Native (XLM)
- Amount (e.g. 5000)

![Stellar transaction source account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljsrkn0yqfwnimj2g6ll.png)

![Stellar transaction destination](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbmzoc3clk95xndp8u0h.png)

Click "Sign in Transaction Signer", enter private key of the source account, click "Submit in Transaction Submitter" and then "Submit Transaction".

![Signing stellar transaction with private key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8cw08u98a4l5bmt5hz1.png)

If everything went well you'll see a success message informing  you that this transaction was a success.

## Checking your balance
Usually you'd check the details of your account on a blockchain explorer like [StellarExpert](https://stellar.expert/explorer/public), but Futurenet is not supported yet, so we'll query the endpoint for our account with Stellar Lab. Open up this [link](https://laboratory.stellar.org/#explorer?resource=accounts&endpoint=single&network=futurenet) and check the response for both of your accounts. The response will contain the information we're looking for somewhere at the bottom in "balances" section.

![Stellar account balance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gg4wf7hra6esafnn3ylf.png)

As you can see our balance has been reduced by the amount we've sent to the receiving account plus a small fee of 0.0000200 XLM.

## Summary
Now that you're familiar with the basics of classic Stellar assets we can move on to designing our own smart contract application with the help of Soroban platform. If you want to learn more [Stellar Quest Learn](https://quest.stellar.org/learn) is a place where you can learn about blockchain and also earn some real XLM for completing the tasks. It's also worth mentioning that in everyday use you'd use a hardware or software wallet instead of Stellar Lab. They make it a lot easier to operate your account.