Skip to content

zzGHzz/thor-jsonrpc-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thor-jsonrpc-server

A local server that implements ETH JSON-RPC APIs for interacting with the VeChain Thor protocol.

Installation

npm i thor-jsonrpc-server

Usage

import { ThorJsonRPCServer } from 'thor-jsonrpc-server';
import { SimpleWallet } from '@vechain/connex-driver';

const wallet = new SimpleWallet();
// Add private key
wallet.import(key);

const srv = new ThorJsonRPCServer(
  url, // Node url, e.g., 
       // Solo node: 	http://127.0.0.1:8669
       // Main net: 	https://sync-mainnet.veblocks.net/	
       // Test net: 	https://sync-testnet.veblocks.net/
  wallet
);

// start the server with a given port
srv.start(port);

Example

  • Request:
{
  "id":1,
  "jsonrpc": "2.0",
  "method":"eth_blockNumber"
}
  • Response
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0x23"
}

Supported ETH JSON-RPC APIs

Name Remark
eth_estimateGas Args:
  • gasPrice can be omitted
eth_blockNumber
eth_getBalance Args:
  • Default block parameter pending not supported
eth_getBlockByNumber
eth_getBlockByHash
Args:
  • Default block parameter pending not supported
Returned block object:
  • hash [32 bytes] - Thor block ID
  • transactions [Array<string>] - always return transaction hashes
  • Unsupported fields: difficulty, totalDifficulty, uncles, sha3Uncles, nonce, logsBloom, extraData
eth_chainId
eth_getCode
eth_getLogs Returned log object:
  • Unsupported fields: transactionIndex, logIndex
eth_getStorageAt
eth_getTransaction Returned transaction object:
  • hash [32 bytes] - Thor transaction ID
  • Unsupported fields: nonce, gasPrice, transactionIndex, maxPriorityFeePerGas, maxFeePerGas
eth_getTransactionReceipt Returned transaction receipt object:
  • Unsupported fields: transactionIndex, cumulativeGasUsed, from, to, logsBloom
eth_isSyncing If under syncing, returned object:
  • currentBlock [Number]
  • highestBlock [Number]
eth_sendTransaction Args:
  • txObj includes fields: from, to, value, data, gas
eth_call Args:
  • gasPrice can be omitted
eth_subscribe
eth_unsubscribe
Args:
  • Supported subscription type: newHeads, logs
eth_gasPrice Return 0
eth_getTransactionCount Return 0
net_version Return 0

License

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

About

Create a WebSocket server for the Thor protocol that implements ETH JSON RPC APIs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published