Connect with Node.js


Connex (opens in a new tab) is the standard interface to connect dApps with VeChain blockchain and users.

For Node.js the connection is a little more complex than for the web:

const { Framework } = require('@vechain/connex-framework')
const { Driver, SimpleNet } = require('@vechain/connex-driver')
const driver = await Driver.connect(new SimpleNet(''))
const connex = new Framework(driver)

For the TestNet use


Once connex is available, the connection works identical to the web-version. See the example here:
How two connect to the Blockchain in the Browser (opens in a new tab)


For an interaction we need to know:

  1. The address of the contract we want to talk to (like an API or Hostname)
  2. The ABI documentation of the function we want to call

For this example the current supply of VTHO will be read, the address for that contract is:


I did look it up in the official docs: (opens in a new tab)

The ABI definition is available in the official docs as well: (opens in a new tab)

For this example only the single function totalSupply() is relevant, it is extracted from the list of all functions defined in the ABI:

const abiTotalSupply = abi.find(({ name }) => name === "totalSupply");


    const result = await connex.thor

result contains a lot of noise. The expected information is found in result.decoded:

{ 0: "52418836757574038600000000000" }

Repeating this on each new block will return the current VTHO supply on the whole network.


The same functionality can be used with parameters. To get the balance of a single address:

const abiBalanceOf = abi.find(({ name }) => name === "balanceOf");
 const { decoded } = await connex.thor
console.log('VTHO Balance:', decoded[0])

call() will verify against the ABI and an error is thrown if data format or number of arguments don't match. Be sure to handle errors correctly.


There is a complete example project running the above example on the command line. You should play around with it: (opens in a new tab)

Also there is a code-sandbox that returns the balance using a webserver: (opens in a new tab)


With the ability to read data from contracts using Node.js APIs or command lines you can now rely on blockchain data.

For example we implemented an access control management using the ownership of a NFT. It moved the full ownership to the user.


  1. Above Example Project (opens in a new tab)
  2. Connex Docs (opens in a new tab)
  3. B32 Collection of ABIs (opens in a new tab)