Learn Reach: Blockchain development only a step away for Javascript developers

The thought of getting into the blockchain space as a developer can be daunting, especially as a Javascript developer who doesn't know any blockchain-relevant programming languages. Examples of these headache languages are:

  • Solidity

  • Vyper

  • Rust

  • Cadence

  • Marlowe

  • Scilla.

Learning any of these programming languages solely for blockchain development may not be time-efficient unless you have enough free time and interest in their other potential uses.

However, if you want to save time, and also leverage your familiarity with Javascript syntax, there's a blockchain language tailored specifically for developers coming from a javascript background. Its name is "Reach".

What is Reach?

Reach is a programming language and a development platform that enables you to write smart contracts for various blockchain networks such as Ethereum, Algorand and Confluence. It makes it easier for developers to create smart contracts by hiding the complicated parts of blockchain development and giving them an easy-to-use interface for writing contracts that are safe and can handle lots of users.

Writing a smart contract has similar financial implications to balancing a spreadsheet. This means the math and logic have to add up to avoid the possible loss of digital assets. Reach solves this problem by emphasizing formal verification, a process that uses mathematical proofs to ensure that a program behaves correctly and is free from such errors and bugs. This implies that if the formal verification process fails, the program will not compile.

Reach has an SDK that can be used with various web frontends, including React, Angular, Next, Vue, Vanilla Javascript Frontend, and React-Native. You build the smart contract with Reach, then connect it to a web frontend using the SDK. This makes it especially super convenient for frontend javascript developers to take on blockchain projects using Reach.

HTML/CSS-phobic folks can test their smart contracts on their console environment using the same SDK.

What does Reach look like?

Here is a code sample for a smart contract that allows a user "Alice" to send 1000 tokens to a user "Bob":

'reach 0.1';

export const main = Reach.App(() => {
    const Alice = Participant('Alice', {});
    const Bob = Participant('Bob', {});

    init();

    Alice.publish().pay(1000);
    commit();

    Bob.publish();

    transfer(balance()).to(Bob);
    commit();
})

Below is a code sample of the same smart contract written in Solidity:

pragma solidity ^0.8.0;

contract TokenTransfer {
    mapping(address => uint256) balances;

    constructor() {
        balances[msg.sender] = 10000;
    }

    function transfer(address recipient, uint256 amount) public {
        require(balances[msg.sender] >= amount, "Insufficient balance");
        balances[msg.sender] -= amount;
        balances[recipient] += amount;
    }

    function getBalance(address account) public view returns (uint256) {
        return balances[account];
    }
}

And then written in Rust:

use near_sdk::{env, near_bindgen, Promise};
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::serde::{Serialize, Deserialize};

#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
#[serde(crate = "near_sdk::serde")]
pub struct Token {
    pub owner_id: String,
    pub balance: u64,
}

impl Token {
    pub fn new(owner_id: String) -> Self {
        Self {
            owner_id,
            balance: 10000, // initialize the balance of the contract deployer to 10000 tokens
        }
    }

    pub fn transfer(&mut self, recipient_id: String, amount: u64) -> Promise {
        assert!(self.balance >= amount, "Insufficient balance");

        self.balance -= amount;

        let mut recipient_token = Token::new(recipient_id.clone());
        recipient_token.balance = amount;
        let promise = Promise::new(recipient_id)
            .function_call(
                b"receive_token".to_vec(),
                borsh::BorshSerialize::try_to_vec(&recipient_token).unwrap(),
                0,
                100000000000000,
            );

        promise
    }

    pub fn get_balance(&self) -> u64 {
        self.balance
    }
}

#[near_bindgen]
#[derive(BorshSerialize, BorshDeserialize)]
pub struct Contract {
    pub token: Token,
}

impl Default for Contract {
    fn default() -> Self {
        Self {
            token: Token::new(env::current_account_id()),
        }
    }
}

#[near_bindgen]
impl Contract {
    pub fn transfer(&mut self, recipient_id: String, amount: u64) -> Promise {
        self.token.transfer(recipient_id, amount)
    }

    pub fn get_balance(&self) -> u64 {
        self.token.get_balance()
    }
}

The code samples show which language would be easiest for a JavaScript developer to learn.

How long will it take me to learn Reach?

That depends on your background in blockchain development.

For a Javascript developer new to blockchain development, the main hurdle to scale at first would be understanding the basic concepts of blockchain development. After which they can then learn how to build with Reach. It took me about 6 weeks to build my first fully functional blockchain app.

For someone who already knows about blockchain development and has some knowledge of a different blockchain language, it may take less time. However, if they have to unlearn concepts from their previous blockchain language, it could take longer.

How can I learn Reach?

To get started with Reach, you'll first have to set up its development environment on your pc. Steps on how to do this can be found in the Reach Documentation. There you'll also find tutorials to ease you into understanding how Reach works.

Reach also has a very active discord community that can answer any questions you may have through the learning process. Here's a link to their discord.

In summary, if you have any doubts about learning Reach, you can take a peek at their discord community. You might get more info about the platform that would help you assess it better.