A simple, beginner-friendly library for reading data from VeChain smart contracts. No complex setup required - just install and call functions! Works with any JavaScript/TypeScript project and integrates seamlessly with existing VeChain SDK projects.
- Install the main package:
# Using yarn
yarn add @vechain/contract-getters
# Using npm
npm install @vechain/contract-getters- Install peer dependencies:
# Using yarn
yarn add @vechain/vechain-contract-types @vechain/sdk-network ethers
# Using npm
npm install @vechain/vechain-contract-types @vechain/sdk-network ethersThere are 4 ways to use VeChain Getters, from simplest to most customized:
import { getVot3Balance } from '@vechain/contract-getters';
// Just call the function - no setup needed!
const balance = await getVot3Balance(
'0x66E9709bc01B8c0AfC99a7dC513f501821306E85',
);
console.log(`Balance: ${balance}`);import { getVot3Balance } from '@vechain/contract-getters';
const balance = await getVot3Balance(
'0x66E9709bc01B8c0AfC99a7dC513f501821306E85',
{
networkUrl: 'https://testnet.vechain.org',
},
);import { ThorClient } from '@vechain/sdk-network';
import { VeChainClient, getVot3Balance } from '@vechain/contract-getters';
// Use your existing ThorClient
const thorClient = ThorClient.at('https://testnet.vechain.org');
const vechainClient = VeChainClient.from(thorClient);
const balance = await getVot3Balance(
'0x66E9709bc01B8c0AfC99a7dC513f501821306E85',
{
client: vechainClient,
},
);import { VeChainClient, getVot3Balance } from '@vechain/contract-getters';
const vechainClient = VeChainClient.create({
nodeUrl: 'https://testnet.vechain.org',
overrideAddresses: {
vot3ContractAddress: '0x6e8b4a88d37897fc11f6ba12c805695f1c41f40e',
// ... other contract addresses
},
});
const balance = await getVot3Balance(
'0x66E9709bc01B8c0AfC99a7dC513f501821306E85',
{
client: vechainClient,
},
);@vechain/contract-getters- Framework-agnostic VeChain getters library with built-in TypeScript support
Check out the examples/nodejs-example/ folder for a complete working example that demonstrates all 4 usage patterns. You can run it with:
yarn example:nodejs- Node.js 18+
- Yarn 1.22+
-
Install dependencies:
yarn install
-
Start core package in watch mode:
yarn core:dev
-
Run example with hot reload:
yarn example:nodejs:dev
yarn core:dev- Start core package in watch modeyarn core:build- Build core packageyarn core:typecheck- Run type checking
yarn build- Build all packagesyarn dev- Start all packages in development modeyarn test- Run tests for all packagesyarn lint- Lint all packagesyarn typecheck- Type check all packagesyarn clean- Clean build artifacts
yarn example:nodejs- Run Node.js exampleyarn example:nodejs:dev- Run Node.js example with hot reload
vechain-getters/
βββ packages/
β βββ contract-getters/ # Core getters library
β βββ src/
β βββ package.json
β βββ tsconfig.json
βββ examples/
β βββ nodejs-example/ # Node.js example app
β βββ src/
β βββ package.json
β βββ README.md
βββ package.json # Root workspace config
βββ README.md # This file
This library provides getters for specific VeChain smart contracts. To add support for new contracts:
-
Create a new contract module in
packages/contract-getters/src/:// packages/contract-getters/src/myContract/balance.ts import { type GetterOptions } from '../types/common'; import { createVeChainClient } from '../client'; export async function getMyContractBalance( address: string, options?: GetterOptions, ): Promise<bigint> { const client = createVeChainClient(options); // Contract interaction logic here // Let smart contract errors bubble up naturally const result = await client.contracts.myContract.balanceOf(address); return result; }
-
Export from module index:
// packages/contract-getters/src/myContract/index.ts export { getMyContractBalance } from './balance';
-
Add to main exports in
packages/contract-getters/src/index.ts:export * from './myContract';
-
Update examples to demonstrate the new getter:
- Add usage examples in
examples/nodejs-example/src/index.ts - Follow existing patterns for error handling and output formatting
- Add usage examples in
Guidelines:
- Keep functions simple and focused on single contract calls
- Let smart contract errors propagate naturally (don't catch unless necessary)
- Use consistent parameter patterns (
address,options?) - Add proper TypeScript types for all parameters and return values
- Follow existing naming conventions (
get[Contract][Function])
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see the LICENSE file for details.