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:
|
web3.eth.getBlockNumber([callback]) |
|
web3.eth.getBalance(address [, callback]) |
|
web3.eth.getBlock(hashOrNumber [, callback]) |
Args:
|
provider.getChainId() |
|
provider.getCode(address [, callback]) |
|
web3.eth.getPastLogs(options [, callback]) |
Returned log object:
|
web3.eth.getStorageAt(address, position [, callback]) |
|
web3.eth.getTransaction(txHash [, callback]) |
Returned transaction object:
|
web3.eth.getTransactionReceipt(hash [, callback]) |
Returned transaction receipt object:
|
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:
|
web3.eth.call(callObject [, callback]) |
Args:
|
web3.eth.subscribe(type [, options] [, callback]) |
Args:
|
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.