Skip to content

Getting Started

Nevio Vesic edited this page Mar 27, 2024 · 8 revisions

Getting Started with SolGo

Welcome to the "Getting Started" guide for SolGo! If you're excited about diving into the world of Solidity parsing with the power of Golang, you're in the right place. This guide will walk you through the initial setup and basic usage of SolGo.

Prerequisites

Before you embark on your journey with SolGo, ensure you have the following:

1. Golang

SolGo is built with Golang, so you'll need it installed on your machine. If you haven't already, follow the official Go installation guide to get started.

2. Setting Up Environment Variable

Before you start, ensure you've set up the required environment variable for the GitHub personal access token:

export SOLC_SWITCH_GITHUB_TOKEN="{your_github_token_here}"

Replace {your_github_token_here} with your actual GitHub personal access token. If you don't have one, you can create it by following the instructions here.

It is used to fetch the latest Solidity compiler releases from the official Solidity GitHub repository. If you don't set it up, you'll get an rate limit error quite quickly.

3. Submodules

In order to access openzeppelin sources submodules needs to be checked out.

make submodules

4. Slither Tool

In order to run audit and discover security vulnerabilities, you need to have slither tool installed.

pip3 install slither-analyzer

Installation

Integrating SolGo into your Go projects is a breeze. To import SolGo, use the following line in your Go program:

import "github.com/unpackdev/solgo"

This will allow you to access all the functionalities that SolGo offers right within your Go environment.

Logger Setup

For efficient and structured logging, SolGo employs the zap logger. Here's a quick guide to set it up:

import (
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

config := zap.NewDevelopmentConfig()
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
logger, err := config.Build()
if err != nil {
	panic(err)
}

zap.ReplaceGlobals(logger)

SolGo adopts a streamlined approach to logging. Instead of passing the logger around, you can use the zap.L() function to retrieve the logger instance wherever needed. This design choice simplifies the logging process, ensuring you can focus on your core tasks without getting bogged down by logger management.

You can look into the zap github repository for more information about it.

NOTE: Not much is logged right now. Will be ensuring in future as one of improvements to add more logging. Logging right now is placed only where it's absolutely essential.

Dive Deeper

Now that you're set up, it's time to explore! Dive into the various features of SolGo, from AST generation to opcode decompilation. The Table of Contents in the Home page, along with the Usage page, provides a roadmap to guide you through the different facets of SolGo.