thorgo

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 10 Imported by: 2

README

Thor GO SDK

thorgo is a Golang library designed to provide an easy and intuitive way to interact with the VeChainThor blockchain. It simplifies blockchain interactions, making it straightforward for developers to build and manage applications on VeChainThor.

Key Features

  • Easy-to-Use Interface: Provides a simple and accessible API for VeChainThor interactions.
  • Blockchain Interaction: Facilitates transactions, smart contract interactions, and more.
  • Golang Support: Leverages the power and efficiency of Go for blockchain development.

Note on Geth

The Thor GO SDK is built on top of the latest version of geth. Familiarity with the Geth repository is encouraged, particularly when working with Application Binary Interfaces (ABIs), cryptographic operations (hashing, signing, and managing private keys), and other low-level blockchain functions. Understanding these elements can help in effectively utilizing the SDK and troubleshooting any related issues.

Installation

To install the Thor GO SDK, run the following command:

go get github.com/darrenvechain/thorgo

Quick Start

package main

import (
	"context"

	"github.com/darrenvechain/thorgo"
	"github.com/darrenvechain/thorgo/thorest"
)

func main() {
	thor := thorgo.New(context.Background(), "https://mainnet.vechain.org")

	blockChan := make(chan *thorest.ExpandedBlock)
	sub := thor.Blocks().Subscribe(blockChan)
	defer sub.Unsubscribe()

	for block := range blockChan {
		println("new block: ", block.Number)
	}
}

CLIs

  • thorgen: A command line tool that generates Go smart contract wrappers for VeChainThor blockchain.

Packages

thorgo
  • github.com/darrenvechain/thorgo
  • thorgo is the primary package in the Thor GO SDK. It provides a high-level interface for interacting with the VeChainThor blockchain. This package includes functions for querying account balances, transactions, blocks, and smart contracts. It also supports simulating, building, and sending transactions, as well as interacting with smart contracts for reading and transacting.
thorest
  • github.com/darrenvechain/thorgo/thorest
  • The thorest package provides raw REST access to the VeChainThor blockchain. It allows developers to query the blockchain directly without the need for higher-level abstractions provided by thorgo.
txmanager
  • github.com/darrenvechain/thorgo/txmanager
  • The txmanager package provides a way to sign, send, and delegate transactions.
  • The delegation managers can be used to easily delegate transaction gas fees.
  • Note: The private key implementations in this package are not secure. It is recommended to use a secure key management solution in a production environment.
  • To create your own transaction manager or signer, you can implement the contracts.TxManager interface:
// github.com/darrenvechain/thorgo/contracts
type TxManager interface {
	SendClauses(clauses []*tx.Clause, opts *transactions.Options) (*transactions.Visitor, error)
}
tx
  • github.com/darrenvechain/thorgo/crypto/tx
  • The tx package is a copy of the vechain/thor/tx package and can be used to build transactions where thorgo does not provide the necessary functionality.
solo
  • github.com/darrenvechain/thorgo/solo
  • The solo package provides quick access to Thor solo values for testing and development purposes.
certificate
  • github.com/darrenvechain/thorgo/crypto/certificate
  • The certificate package provides a way to encode, sign, and verify certificates in accordance with VIP-192
hdwallet
  • github.com/darrenvechain/thorgo/crypto/hdwallet
  • The hdwallet package provides a way to generate HD wallets and derive keys from them.

Examples

1) Contract Generation with thorgen CLI
  • See gen.go for an example of generating a smart contract wrapper using the thorgen CLI.
  • Run go generate in the internal/examples/contractgen directory to generate the contract wrapper.
  • See the usage at echo_test.go.
2) Delegated Transaction
  • See delegated_tx.go for an example of sending a delegated transaction using the txmanager package.
3) Multi Clause Transaction
4) Hardhat Integration
  • thorgen can natively generate contract bindings for smart contract artifacts produced by Hardhat.
  • See gen.go and counter.go for an example of generating a smart contract wrapper using Hardhat artifacts.
5) Custom Transaction Building
  • See custom_tx.go to see how to build, simulate and send transactions with custom options.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Thor

type Thor struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, url string) *Thor

New creates a new instance of the Thor client with the given context and URL.

func NewFromClient

func NewFromClient(ctx context.Context, c *thorest.Client) *Thor

NewFromClient creates a new instance of the Thor client with the given context and thorest client.

func (*Thor) Account

func (t *Thor) Account(address common.Address) *accounts.Visitor

Account can be used to query account information such as balance, code, storage, etc. It also provides a way to interact with contracts.

func (*Thor) Blocks

func (t *Thor) Blocks() *blocks.Blocks

Blocks provides utility functions to fetch or wait for blocks.

func (*Thor) Client

func (t *Thor) Client() *thorest.Client

Client returns the underlying thorest client.

func (*Thor) Deployer

func (t *Thor) Deployer(bytecode []byte, abi *abi.ABI) *contracts.Deployer

Deployer makes it easier to deploy contracts.

func (*Thor) Events

func (t *Thor) Events() *logs.EventFilterer

Events sets up a query builder to fetch smart contract solidity events.

func (*Thor) Transaction

func (t *Thor) Transaction(hash common.Hash) *transactions.Visitor

Transaction provides utility functions to fetch or wait for transactions and their receipts.

func (*Thor) Transactor

func (t *Thor) Transactor(clauses []*tx.Clause) *transactions.Transactor

Transactor creates a new transaction builder which makes it easier to build, simulate and send transactions.

func (*Thor) Transfers

func (t *Thor) Transfers() *logs.TransfersFilterer

Transfers sets up a query builder to fetch VET transfers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL