maht0rz / granary

Tezos smart contract & dapp development toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Granary 🌾

Tezos environment manager & smart contract development toolkit

This project is a WIP, contact t.me/maht0rz for any questions

Tezos environment manager provides a seamless way to develop smart contracts and dapps locally for public networks such as alphanet, and private networks such as sandboxnet

alphanet environment is currently WIP

Sections of readme with 'πŸ– ' are only applicable to the sandboxnet environment

πŸ‘€ Quick overview

Block explorer for sandboxnet

Sending a transaction using sandboxnet

Deploying a ReasonML smart contract at sandboxnet

πŸ›  Setup

1. Choose an environment / network

source ./env/sandboxnet.sh

2. Start the apropriate tezos node

make start

3. Open the interactive shell with tezos-client and liquidity preconfigured

⚠️   All Tezos related commands will be ran inside this shell

make client

Inside the newly started shell, initialize the tezos-client by running:

# Run this inside the shell created by make client
init-client

⚠️ tezos-client needs to be initialised only once, unless you delete/restart your bootstrapped network.

4. Confirm the setup by navigating to local TzScan

TzScan is available at http://localhost:8000/.

You should see your sandboxed network with no transactions at block 1, baked by God.

πŸ•Ή Useful commands

Miscelanious

Initializing the sandbox client

When you start your sandboxnet node for the first time, make sure to initialize your client in order to get a handful of testing accounts to play with.

init-client

Client

List all available addresses

tezos-client list known addresses

Create a transfer using tezos-client

tezos-client transfer 1000 from bootstrap1 to bootstrap2 &

πŸ–   Bake a new block

tezos-client bake for bootstrap1

Check your balance

tezos-client get balance for bootstrap2

Contracts

You can find an example smart contract, in all three supported syntaxes: .liq .reliq .tz, under src/contracts/

⚠️ Prievously we've encouraged the use of refmt to convert .re files into .liq files, but liquidity now supports ReasonML syntax out of the box, you can learn more here.

Simulating a smart contract execution

liquidity \
    --tezos-node $NODE_URL \
    --amount 2tz \
    tezos-environment-manager/src/contracts/simple.liq \
    --run main '5' '1'

The command above, will test our simple.liq smart contract, by calling it's entry point main, with it's single argument as 1, while setting it's initial storage value to 5.

Forging a contract deployment

⚠️ $NODE_URL is set based on your environment automatically

liquidity \
        --tezos-node $NODE_URL \
        --amount 2tz \
        --fee 1tz \
        --delegatable \
        --source tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx \
        tezos-environment-manager/src/contracts/simple.liq \
        --forge-deploy > contract_deployment_op.bytes

Signing a forged operation

tezos-client sign bytes 0x03$(cat ./contract_deployment_op.bytes) for bootstrap1

Injecting a signed operation

liquidity \
   --tezos-node $NODE_URL \
   --signature signature_goes_here \
   --inject contract_deployment_op.bytes

πŸ–  Don't forget to bake a new block after injecting an operation

Getting a receipt for an injected operation

You can use the following command, to get the originated address of your contract. (e.g. KT1GtgAL2VV2R9McZmhPxTp5syB4ysyG2XL1)

tezos-client get receipt for operation_hash_goes_here

Display private key for an account

tezos-client show address  bootstrap1 -S

Using ReasonML for Liquidity contracts

Liquidity supports syntax of ReasonML in the form of .reliq files, instead of the traditional .liq files.

If your file has a .reliq extension, it'll be automatically parsed as ReasonML.

liquidity \
    --tezos-node $NODE_URL \
    --amount 2tz \
    tezos-environment-manager/src/contracts/simple.reliq \
    --run main '5' '1'

πŸ” Block explorer

Once your local environment is up & running, you can visit the block explorer (tzscan) at http://localhost:8000

Don't forget to bake a new block after you inject any operations using the client.

πŸ‘·β€ Listing of all existing blocks does not seem to work at the moment, however dashboard displays blocks as it should

πŸ“š Examples

RPC with Sotez

You can find an attached example of sotez.node.query in the examples/ folder.

Running the examples

You will need a recent version of NodeJS installed locally

  1. Install dependencies
npm install
  1. Run the example
# Get current block/head
npm run head
# Get storage of a deployed smart contract
# Make sure your contract is deployed and the example address is up-to-date
npm run contract

πŸš— Roadmap

  • Automated contract deployment & testing in ReasonML / OCaml & bs-jest
  • Alphanet support

About

Tezos smart contract & dapp development toolkit

License:MIT License


Languages

Language:Shell 82.2%Language:Dockerfile 15.1%Language:Makefile 2.8%