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.
- 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.
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.
To install the Thor GO SDK, run the following command:
go get github.com/darrenvechain/thorgopackage 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)
}
}- thorgen: A command line tool that generates Go smart contract wrappers for VeChainThor blockchain.
github.com/darrenvechain/thorgothorgois 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.
github.com/darrenvechain/thorgo/thorest- The
thorestpackage provides raw REST access to the VeChainThor blockchain. It allows developers to query the blockchain directly without the need for higher-level abstractions provided bythorgo.
github.com/darrenvechain/thorgo/txmanager- The
txmanagerpackage 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.TxManagerinterface:
// github.com/darrenvechain/thorgo/contracts
type TxManager interface {
SendClauses(clauses []*tx.Clause, opts *transactions.Options) (*transactions.Visitor, error)
}github.com/darrenvechain/thorgo/crypto/tx- The
txpackage is a copy of the vechain/thor/tx package and can be used to build transactions wherethorgodoes not provide the necessary functionality.
github.com/darrenvechain/thorgo/solo- The
solopackage provides quick access to Thor solo values for testing and development purposes.
github.com/darrenvechain/thorgo/crypto/certificate- The
certificatepackage provides a way to encode, sign, and verify certificates in accordance with VIP-192
github.com/darrenvechain/thorgo/crypto/hdwallet- The
hdwalletpackage provides a way to generate HD wallets and derive keys from them.
- See gen.go for an example of generating a smart contract wrapper using the
thorgenCLI. - Run
go generatein theinternal/examples/contractgendirectory to generate the contract wrapper. - See the usage at echo_test.go.
- See delegated_tx.go for an example of sending a delegated transaction using the
txmanagerpackage.
- See multi_clause_tx.go for an example of sending a multi-clause transaction.
thorgencan 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.
- See custom_tx.go to see how to build, simulate and send transactions with custom options.