项目作者: hexoul

项目描述 :
Web3 wrapper for ERC721, 725, 735 and governance
高级语言: JavaScript
项目地址: git://github.com/hexoul/meta-web3.git
创建时间: 2018-12-04T00:42:43Z
项目社区:https://github.com/hexoul/meta-web3

开源协议:MIT License

下载


meta-web3

License
NPM
JavaScript Style Guide

Web3 wrapper for ERC721, 725, 735 and governance

Install

  1. npm i meta-web3

Components

  1. Registry
  2. AttestationAgencyRegistry
  3. Identity
  4. IdentityManager
  5. TopicRegistry
  6. AchievementManager
  7. BallotStorage
  8. EnvStorage
  9. Governance
  10. Staking

Usage

  1. import React, { Component } from 'react'
  2. // Web3
  3. import Web3 from 'web3';
  4. import web3config from './web3-config.json'
  5. // Contracts
  6. import { constants, contracts, getContractsAddresses, initContracts, TopicRegistry } from 'meta-web3'
  7. class Example extends Component {
  8. state = {
  9. initDone: false,
  10. };
  11. async init() {
  12. initContracts({
  13. web3: new Web3(new Web3.providers.HttpProvider(web3config.url)),
  14. branch: constants.branch.TESTNET,
  15. identity: web3config.identity,
  16. privkey: web3config.privkey,
  17. }).then(async () => {
  18. // All contracts are initialized
  19. this.result = {
  20. getLengthOfAchievements: await contracts.achievementManager.getLengthOfAchievements(),
  21. getAttestationAgencyNum: await contracts.aaRegistry.getAttestationAgencyNum(),
  22. getTotal: await contracts.topicRegistry.getTotal(),
  23. };
  24. this.setState({ initDone: true })
  25. });
  26. }
  27. async initDirectly() {
  28. // If you want to initialize each contract directly
  29. getContractsAddresses().then(async () => {
  30. let topicRegistry = new TopicRegistry()
  31. topicRegistry.init({
  32. web3: new Web3(new Web3.providers.HttpProvider(web3config.url)),
  33. }).then(async () => {
  34. let total = await topicRegistry.getTotal()
  35. console.log('total', total)
  36. });
  37. });
  38. }
  39. componentWillMount() {
  40. this.init();
  41. }
  42. render () {
  43. return (
  44. <div>
  45. {this.state.initDone &&
  46. Object.keys(this.result).map(k => <p key={k}>{k + ': ' + this.result[k]}</p>)
  47. }
  48. </div>
  49. )
  50. }
  51. }

Test

  1. cd meta-web3
  2. npm start
  3. [Ctrl+C]
  4. cd example
  5. npm start

Reference