Web3.js provider to interact with the VeChain Thor protocol

Overview

web3-providers-connex

Web3.js provider implemented using Connex.js. It makes it possible to use web3.js and ethers.js to interact with VeChain Thor protocol.

Installation

npm i web3-providers-connex

Usage

To create a web3 object:

import * as thor from 'web3-providers-connex';

// connex is an object of Connex
const provider = new thor.ConnexProvider({ connex: connex });
const web3 = new Web3(provider);

To create an ethers JsonRpcProvider:

import * as thor from 'web3-providers-connex';

// connex is an object of Connex
const provider = thor.ethers.modifyProvider(
	new ethers.providers.Web3Provider(
		new thor.ConnexProvider({ connex: connex })
	)
);

To create an ethers JsonRpcSigner:

const signer = provider.getSigner(addressOrIndexOrUndefined);

To deploy a contract

const factory = thor.ethers.modifyFactory(
	new ethers.ContractFactory(abi, bin, signer)
);
const contract = await factory.deploy(...args);

Methods modifyProvider and modifyFactory are used to replace methods jsonRpcProvider.sendTransaction and contractFactory.deploy shipped with ethers.js to bypass the contract address computation that is incompatible with the Thor protocol.

APIs

Tested web3 API Remark
web3.eth.estimateGas(callObject [, callback]) Args:
  • callObject includes properties: from, to, value, data, gas
web3.eth.getBlockNumber([callback])
web3.eth.getBalance(address [, callback])
web3.eth.getBlock(hashOrNumber [, callback]) Args:
  • hashOrNumber cannot be "pending"
Returned block object:
  • hash [32 bytes] - Thor block ID
  • transactions [Array<string>] - always return transaction hashes
  • null properties difficulty, totalDifficulty, uncles, sha3Uncles, nonce, logsBloom, extraData, baseFeePerGas [`null
provider.getChainId()
provider.getCode(address [, callback])
web3.eth.getPastLogs(options [, callback]) Returned log object:
  • 1. transactionIndex = -1
  • 2. logIndex = -1
web3.eth.getStorageAt(address, position [, callback])
web3.eth.getTransaction(txHash [, callback]) Returned transaction object:
  • hash - Thor transaction ID
  • nonce = -1
  • null properties: gasPrice, transactionIndex
  • undefined properties: maxPriorityFeePerGas, maxFeePerGas
  • thor [Connex.Thor.Transaction]
web3.eth.getTransactionReceipt(hash [, callback]) Returned transaction receipt object:
  • transactionIndex = -1
  • cumulativeGasUsed = -1
  • null properties: from, to, cumulativeGasUsed, effectiveGasPrice
  • undefined properties: logsBloom, events
  • thor [Connex.Thor.Transaction.Receipt]
Returned log object:
  • transactionIndex = -1
  • logIndex = -1
web3.eth.isSyncing([callback]) If under syncing, returned object:
1. currentBlock [Number]
2. highestBlock [Number]
3. thor [Connex.Thor.Status]
web3.eth.sendTransaction(txObject [, callback]) Args:
  • txObject includes properties: from, to, value, data, gas
web3.eth.call(callObject [, callback]) Args:
  • callObject includes properties: from, to, value, data, gas
web3.eth.subscribe(type [, options] [, callback]) Args:
  • `type = "newBlockHeaders
web3.eth.Contract
Tested ethers API Remark
provider.estimateGas(transaction)
provider.getBlockNumber()
provider.getBalance(address)
provider.getBlock(block)
provider.getCode(address)
provider.getLogs(filter)
provider.getTransaction(hash)
provider.getTransactionReceipt(hash)
jsonRpcProvider.getSigner([addressOrIndex])
jsonRpcProvider.sendTransaction(transaction) This method is re-implemented via calling modifyProvider
ethers.Contract
ethers.ContractFactory Method contractFactory.deploy is re-implemented via calling modifyFactory

Examples

See tests for more examples.

License

This software is licensed under the GNU Lesser General Public License v3.0, also included in LICENSE file in repository.

You might also like...

Mercure Provider - Real-time Made Easy

Mercure Provider - Real-time Made Easy

@setten/mercure is a Mercure client for AdonisJS. Mercure allows you to use Server Sent Events to push data to your clients using Http. Note You must

Nov 29, 2022

📊🌍 Super small, light, privacy-focused, self-hostable web statistics provider

📊🌍 Super small, light, privacy-focused, self-hostable web statistics provider

femtostats Update: It turns out Fathom Lite does everything I wanted to do except custom events for free, so I'm going to stop working on this for now

Nov 17, 2022

Nami Wallet is a browser based wallet extension to interact with the Cardano blockchain.

Nami Wallet Nami Wallet is a browser based wallet extension to interact with the Cardano blockchain. It's an open-source project and built by Berry Po

Dec 29, 2022

A package that allows your bot of discord.js v13 & v14 to create the new awesome Discord Modals and interact with them

A package that allows your bot of discord.js v13 & v14 to create the new awesome Discord Modals and interact with them

A package that allows your bot of discord.js v13 & v14 to create the new awesome Discord Modals and interact with them

Dec 23, 2022

A standard library to interact with KaiOS 2.x and 3.x APIs.

kaios-lib A standard library to interact with KaiOS 2.x and 3.x* APIs. * 3.x support coming when there is a good dev device available for testing purp

Jun 3, 2022

Complete module to interact with the Brawl Stars API.

BrawlStars-API.js Brawlstars-api.js is a library made to interact with the Official Brawl Stars api, listing all of their endpoints in one place. ✨ Ho

Nov 3, 2022

A comprehensive collection of useful tools developed with the help of Ethers.js to interact with the Ethereum Blockchain to develop great DeFi apps as quickly and easily as possible.

hudi-packages-ethersfactory How to install Installing with npm For more information on using npm check out the docs here. npm i @humandataincome/ether

Mar 30, 2022

A simple API to interact with Stacks and CityCoins data.

CityCoins API Probably Nothing CF Workers + IttyRouter + micro-stacks + TypeScript ...and it feels good! Things to Note uses simple typed responses an

Oct 10, 2022

Get, change, and otherwise interact with your notes in Obsidian via a REST API.

Local REST API for Obsidian See our interactive docs: https://coddingtonbear.github.io/obsidian-local-rest-api/ Have you ever needed to automate inter

Dec 22, 2022
Comments
  • LogIndex and TransactionIndex of events are always 0

    LogIndex and TransactionIndex of events are always 0

    Transaction and log indices, contained in logs and receipts can be used to check transaction & event orders, and generally enhance audit ability.

    When formatted, these are always set to 0: https://github.com/vechain/web3-providers-connex/blob/e4fc5fd8a4713b475453d2ced217e1ecc3cdebee/src/formatter.ts#L249-L250 https://github.com/vechain/web3-providers-connex/blob/e4fc5fd8a4713b475453d2ced217e1ecc3cdebee/src/formatter.ts#L329-L330

    Since it is possible (but more expensive) to obtain them, we suggest to add flags to the Formatter and Provider's constructors, e.g.:

    • includeLogIndex
    • includeTxIndex

    to allow users to opt-in to this information, by fetching it while formatting, only these flags are set.

    opened by andreas-papageorgiou 1
Owner
null
Web3 NPM library to interact with Soonaverse.

Soonaverse - Soonaverse JavaScript/Typescript API - APLHA Please note this is APLHA and we might introduce breaking changes. Library to interact with

SoonLabs 15 Oct 28, 2022
Web3 NPM library to interact with Soonaverse.

Soonaverse - Soonaverse JavaScript/Typescript API - APLHA Please note this is APLHA and we might introduce breaking changes. Library to interact with

Soonaverse 12 Apr 27, 2022
Web3-citizens-app - React application based on smart contract using web3 and MetaMask extention.

Citizens App (web3-react-redux) React application based on smart contract using web3 and MetaMask extention. Start the applicarion Recomend to install

Denys Voloshyn 3 Aug 25, 2022
A web3 starter project using Typescript, Hardhat, ethers.js and @web3-react

Starter React Typescript Ethers.js Hardhat Project This repo contains a Hardhat and React Dapp starter project. The React Dapp in the frontend dir of

ChainShot 39 Dec 31, 2022
(🔗, 🌲) Web3 Link Tree is a free & open-source alternative to Linktree built with React.js, Next.js, Tailwind and Web3-React

Getting Started Read the detailed guide here Customize Add your name, wallet address, social media links and more in config.ts Images Save images to t

Naut 35 Sep 20, 2022
🛠 Solana Web3 Tools - A set of tools to improve the user experience on Web3 Solana Frontends.

?? Solana Web3 Tools - A set of tools to improve the user experience on Web3 Solana Frontends.

Holaplex 30 May 21, 2022
Use Matrix as a backend for local-first applications with the Matrix-CRDT Yjs provider.

Matrix CRDT Matrix-CRDT enables you to use Matrix as a backend for distributed, real-time collaborative web applications that sync automatically. The

Yousef 604 Jan 7, 2023
🌱 Ethereum provider solution for Dapp&Wallets, 🏷 If you have good suggestions, please submit issues

English | įŽ€äŊ“中文 | æ—ĨæœŦ ETH Wallet Modal An Ethereum Provider Solution for Integrated Wallets and Dapps ⚠ī¸ Notice If you need to reduce unnecessary import

Dan Xu 35 Dec 19, 2022
☁ī¸ Application using Node.js, AdonisJs, Adonis ACL, Adonis Kue Provider, Adonis Mail, Adonis Lucid Slugify, Adonis Validator, AdonisJs Redis, ESLint and pg

Node.js - SaaS ☁ī¸ Application using Node.js, AdonisJs, Adonis ACL, Adonis Kue Provider, Adonis Mail, Adonis Lucid Slugify, Adonis Validator, AdonisJs

null 4 Aug 19, 2022
Cross provider map drawing library, supporting Mapbox, Google Maps and Leaflet out the box

Terra Draw Frictionless map drawing across mapping providers. TerraDraw centralises map drawing logic and provides a host of out the box drawing modes

James Milner 106 Dec 31, 2022