项目作者: vechain

项目描述 :
A web3 adaptor for VeChain Thor RESTful HTTP API.
高级语言: TypeScript
项目地址: git://github.com/vechain/thorify.git
创建时间: 2018-04-25T09:59:32Z
项目社区:https://github.com/vechain/thorify

开源协议:MIT License

下载


Thorify

[!IMPORTANT]
This project is discontinued, try out web3-providers-connex or vechain-sdk-js.

NPM Version
Build Status
Coverage Status

A web3 adaptor for VeChain Thor RESTful API.

Table of contents

Install

  1. npm i thorify web3@1.* # Web3 is needed as dependency.

Furthermore, if you would like to change web3 version after installation, for example 1.6, run npm i web3@1.6 web3-core-subscriptions@1.6 as subscriptions is a peer dependency.

Usage

  1. // ES6 style
  2. import { thorify } from "thorify";
  3. const Web3 = require("web3"); // Recommend using require() instead of import here
  4. const web3 = thorify(new Web3(), "http://localhost:8669");
  5. web3.eth.getBlock("latest").then(res => console.log(res));
  6. // Best block info will be displayed

If you would like to write code in ES5, check below for the initialization code.

  1. // ES5 style
  2. const thorify = require("thorify").thorify;
  3. const Web3 = require("web3");
  4. const web3 = thorify(new Web3(), "http://localhost:8669");
  5. web3.eth.getBlock("latest").then(res => console.log(res));
  6. // Best block info will be displayed

Web3 method supported

  1. web3 instance
  2. ├── eth
  3. ├── getBlockNumber
  4. ├── getBalance
  5. ├── getStorageAt
  6. ├── getCode
  7. ├── getBlock
  8. ├── getTransaction
  9. ├── getTransactionReceipt
  10. ├── sendTransaction
  11. ├── sendSignedTransaction
  12. ├── call
  13. ├── estimateGas
  14. ├── getPastLogs
  15. ├── subscribe
  16. ├── clearSubscriptions
  17. ├── getEnergy
  18. ├── getChainTag
  19. ├── getBlockRef
  20. ├── accounts
  21. └── Contract
  22. ├── Constructor(new Contract())
  23. ├── clone
  24. ├── deploy
  25. ├── methods
  26. ├── methods.myMethod.call
  27. ├── methods.myMethod.send
  28. ├── methods.myMethod.estimateGas
  29. ├── methods.myMethod.encodeABI
  30. ├── events
  31. ├── once
  32. ├── events.myEvent
  33. ├── events.allEvents
  34. └── getPastEvents
  35. └── utils

Send Transaction

In Thor official implementation , the client DOES NOT neither manage user’s private-key/keyStore nor use private key to sign a Transaction. Unfortunately, thorify can not directly perform eth_sendTransaction but there is another way to sign a transaction.

In web3.js accounts, it gives the opportunity to add your private-key, stored in your runtime context (In Node.js context, it’s stored in memory while in Browser context, it’s stored in memory/local storage), to accounts module. When you are trying to send a transaction, the module will check the private key associated with from field. Once the private key and from have been matched, the module will sign the transaction.
The APIs that follows the mechanism are:

  • web3.eth.sendTransaction()
  • contract.deploy.send()
  • contract.methods.myMethod.send()

Documentation

API Reference

Play with multi-clause

  1. thor-devkit.js supports multi-clause and sign transaction
  2. send signed transaction using sendSignedTransaction

FAQ

How do I send VTHO token

VTHO is a token that compatible with VIP180(ERC-20), you can build a contract instance using web3 and do what ever you want.

Multi party payment protocol or sponsored contract

It’s done by calling the functions of prototype contract, check wiki page) for detailed info about prototype contract.

Method not supported

The RESTful API of Thor is different with Ethereum’s JSON-RPC, therefore, there are some methods in web3 are not supported by thorify, feel free to open an issue discuss the features.

Notes

  • There are three special block number in Ethereum: earliest,latest,pending. In VeChain Thor, we introduced best block and there is no pending block, so they will be replaced with 0 (aka genesis), best, best

Compatibility

Currently, Thorify is compatible with web3@1.*, tested versions are 1.2~1.7.1.

Debugging

  1. DEBUG=thor:* ts-node index.ts

ts-node index.ts can be replaced with command to run your code, this example is only for Node.js environment. For more detailed info, please refer to debug.

License

This project is licensed under the MIT license, Copyright (c) 2017 VeChain Foundation. For more information see LICENSE.md.