🐙 Web3 blockchain bindings for Vue.js (inspired by Vuefire and Drizzle)

Overview

VueWeb3 Build Status npm package

Vue.js bindings for Web3 1.0

Installation

In module environments, e.g CommonJS:

npm install vue [email protected] vue-web3
var Vue = require('vue')
var Web3 = require('web3')
var VueWeb3 = require('vue-web3')

// explicit installation required in module environments
Vue.use(VueWeb3, { web3: new Web3(web3.currentProvider) })

Usage

let myContract = new web3.eth.Contract(MyContract, '0xbA911C4A817e69998Ffd3626d3c5366038e8480F')

var vm = new Vue({
  el: '#demo',
  web3: {
    // can bind to calls
    lastUpdated: {
      contract: myContract,
      method: 'getLastUpdated',
      arguments: []
    },
    // can also bind to events
    transfers: {
      contract: myContract,
      event: 'OwnershipTransferred',
      options: {
        fromBlock: 2
      }
    }
  }
})

If you need to access properties from the Vue instance, use the function syntax:

var vm = new Vue({
  el: '#demo',
  web3: function () {
    return {
      lastUpdated: {
        contract: myContract,
        method: 'getLastUpdated',
        arguments: [this.$store.state.user.uid]
      }
    }
  }
})

⚠️ : This function will get executed only once. If you want to have automatic rebind (pretty much like a computed property) use a $watch and call $unbind and then $bindCall or $bindEvents

<div id="demo">
  <pre>{{ lastUpdated }}</pre>
  <ul>
    <li v-for="transfer in transfers">From {{ transfer.previousOwner }} to {{ transfer.newOwner }}</li>
  </ul>
</div>

The above will bind the Vue instance's lastUpdated and transfers to the respective Web3 data sources.

Alternatively, you can also manually bind to Web3 with the $bindCall or $bindEvents instance methods:

let myContract = new web3.eth.Contract(MyContract, '0xbA911C4A817e69998Ffd3626d3c5366038e8480F')
vm.$bindCall('user', { contract: myContract, method: 'getUser' })
vm.$bindEvents('transfers', { contract: myContract, event: 'OwnershipTransferred' })

// References are unbound when the component is destroyed but you can manually unbind a reference
// if needed
vm.$unbind('items')

Error: The current provider doesn't support subscriptions: MetamaskInpageProvider

In order to get updates from the blockchain, this library requires a provider that supports subscriptions. MetaMask does not currently inject a provider with this support, this is being tracked via metamask-extension/2350.

Thankfully, we can create our own provider:

var provider = new Web3.providers.WebsocketProvider('wss://ropsten.infura.io/ws')

Until MetaMask's provider supports subscriptions, you can have a write web3 instance with MetaMask's provider and a read web3 instance which uses the WebsocketProvider.

Contributing

Clone the repo, then:

$ npm install    # install dependencies
$ npm test       # run test suite with coverage report
$ npm run dev    # watch and build dist/vue-web3.js
$ npm run build  # build dist/vue-web3.js and vue-web3.min.js

License

MIT

You might also like...
Simple state management whitout bloating API and Concept for Vue.js.
Simple state management whitout bloating API and Concept for Vue.js.

Vue Freeze Simple state management whitout bloating API and Concept. Just states and actions. And also It will keep your state immutable. Vue Freezer

A solution to simplify import and use of Vue.js components

vue-import-and-use A solution to simplify import and use of Vue.js components Instalation $ npm install --save vue-import-and-use Without vue-import-a

🚀 Build .NET desktop applications using HTML, CSS and javascript.
🚀 Build .NET desktop applications using HTML, CSS and javascript.

Neutronium https://neutroniumcore.github.io/Neutronium/ What is Neutronium? Neutronium is a library to create .NET desktop applications using HTML, CS

Vuejs integration for Ionic versions 4 and 5
Vuejs integration for Ionic versions 4 and 5

Ionic-Vue Ionic integration adapters for Vue. Ionic-Vue vs @ionic/vue Ionic-Vue codebase has been contributed to the Ionic core and as @ionic/vue. How

This is a WebApp for Arbitrium API, you can use to access the targets devices in a simple and interactive way

Arbitrium WebApp This web interface is still in developpement, but it allows you to easily use the different features of ArbitriumRAT, the WebApp also

Vite 2 plugin that works with the dev server and rollup build.

vite-eslint Vite 2 plugin that works with the dev server and rollup build. Any errors from eslint should appear in the Vite overlay. Warning You proba

An intuitive observability client for @sherlog/cli. Replay and drill down through multiple log types as data is piped in
An intuitive observability client for @sherlog/cli. Replay and drill down through multiple log types as data is piped in

Sherlog Prisma An intuitive observability client for @sherlog/cli. Replay and drill down through multiple log types as data is piped in Demo: https://

A Vue.js component that provides "Add to Calendar" functionality, works with Vue 2.X

Vue Add To Calendar A Vue.js renderless component providing 'Add to Calendar' functionality Less than 1kb gzipped Demo What is a renderless component?

Vue Custom Element - Web Components' Custom Elements for Vue.js
Vue Custom Element - Web Components' Custom Elements for Vue.js

Finally - official Web Components implementation! - check vuejs/vue-web-component-wrapper Table of contents Demo Installation Description Example Shad

Comments
  • fyi issue with web3 beta 34 and 35

    fyi issue with web3 beta 34 and 35

    Configuring subscriptions I got this error:

    WebSocket connection to 'wss://ropsten.infura.io/ws' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received

    As described here, it's an issue in web3 beta34/35, so stick on 33 or use the 1.0 branch.

    opened by paolodina 1
  • error

    error

    ERROR in ./node_modules/web3/packages/web3-utils/src/utils.js Module not found: Error: Can't resolve 'eth-lib/src/hash' in '/Users/xueqingli/Documents/node.js项目/EtherDice_Web/node_modules/web3/packages/web3-utils/src' @ ./node_modules/web3/packages/web3-utils/src/utils.js 27:11-38 @ ./node_modules/web3/packages/web3-utils/src/index.js @ ./node_modules/web3/src/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main

    ERROR in ./node_modules/web3/packages/web3-utils/src/index.js Module not found: Error: Can't resolve 'ethjs-unit' in '/Users/xueqingli/Documents/node.js项目/EtherDice_Web/node_modules/web3/packages/web3-utils/src' @ ./node_modules/web3/packages/web3-utils/src/index.js 26:16-37 @ ./node_modules/web3/src/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main

    ERROR in ./node_modules/web3/packages/web3-utils/src/index.js Module not found: Error: Can't resolve 'randomhex' in '/Users/xueqingli/Documents/node.js项目/EtherDice_Web/node_modules/web3/packages/web3-utils/src' @ ./node_modules/web3/packages/web3-utils/src/index.js 29:16-36 @ ./node_modules/web3/src/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main

    opened by jeremy16601 1
  • hi,我在用的过程中出现了这个错误

    hi,我在用的过程中出现了这个错误

    ERROR in ./node_modules/vue-web3/dist/vue-web3.esm.js Module not found: Error: Can't resolve 'web3' in 'D:\nodejs-Project\EtherDice_Web\node_modules\vue-web3\dist' @ ./node_modules/vue-web3/dist/vue-web3.esm.js 1:6-21 @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./src/main 麻烦帮忙看下吧,谢谢

    opened by jeremy16601 1
  • Cannot read property 'blockNumber' of undefined

    Cannot read property 'blockNumber' of undefined

    Hello! I'm getting the error below related to event bind.

    Error: vue-web3.esm.js?537a:1 Uncaught (in promise) TypeError: Cannot read property 'blockNumber' of undefined at Vue.eval (vue-web3.esm.js?537a:1)

    Relevant code:

    var myContract;
    if (typeof window.web3 !== "undefined") {
        let web3js = new Web3(window.web3.currentProvider);
        Vue.use(VueWeb3, { web3: web3js });
        myContract = new web3js.eth.Contract(
          MyContract.abi, "0x...");
    }
    
    new Vue({
        data: () => ({
          items: []
        }),
        web3: () => ({
          items: {
            contract: myContract,
            event: "MyEvent"
          }
        })
    })
    

    Environment: Chromium 70.0.3538.77 MetaMask 5.0.2 web3 1.0.0-beta.36 vue-web3 2.1.0

    EDIT: My contract in local geth instance hasn't emitted events yet. Looking at source code, maybe line 59 requires some past event:

    options.fromBlock = events[events.length - 1].blockNumber + 1;
    
    opened by rpn80 0
Releases(v2.1.0)
intro.js bindings for Vue.

vue-introjs intro.js bindings for Vue. Installation Add package yarn add vue-introjs # or via npm: npm i vue-introjs Install plugin import VueIntro f

Alex Oleshkevich 299 Dec 12, 2022
A vue component library incubated from Tencent BlueKing which helps OPS in the field of front-end engineering to quickly build stable, accurate, and technologically-sense operation and maintenance tools and platforms

English | 简体中文 bk-vue-cec 基于蓝鲸 bk-magic-vue 修改风格并修复bug后的组件库,由DAO(去中心化自治组织)维护,收录于ti-design体系,请注意,其中cec表示community edtion components(社区版组件),并不是代表China E

T-inside 81 Jun 29, 2022
[DEPRECATED] Jest preprocessor.js for Vue.js components (supporting html, pug, and babel) and TypeScript

❄️ DEPRECATION NOTICE ❄️ Official TypeScript and Jest support has been added to Vue.js 2.x, which has changed considerably since this repository has b

Locoslab GmbH 16 Dec 1, 2018
RequireJS plugin to async and dynamic load and parse .vue components

require-vuejs RequireJS plugin to async and dynamic load and parse .vue single file components This library has only 4Kb ( minified ). What this libra

Edgard Rosberg Duarte Leal 146 Feb 25, 2022
A Vue project template with Loopback framework optionally with Vuex, Vue-router, and Auth boilerplaite

vue-loopback A Vue project template with Loopback framework featuring ES6, Gulp, and Jest for unit tests This template is for Vue 2.x only with vue-cl

InCuca Tech 52 Nov 18, 2021
A starter template for LoopBack 3.x And Vue 2.x with support for the new vue-cli v3

LoopBack Vue Starter The LoopBack Vue Starter template has a very minimal set of features pre-enabled. The starter template uses LoopBack v3.x for API

Ivan Dovgan 19 Nov 24, 2022
Vue component to integrate Disqus count and comments in your application, with support for SPA

vue-disqus Vue component to integrate Disqus comments in your application Vue.js, with support for SPA and Vue 2.* Links Documentation Demo Contributi

Alan Ktquez 252 Dec 30, 2022
Vue.js and YouTube

Vue YouTube Embed This is a component for Vue.js to utilize YouTube iframe API easily. This is based on Angular YouTube Embed License MIT License inst

null 419 Dec 30, 2022
Integration of FeathersJS, Vue, and Nuxt for the artisan developer

Feathers-Vuex Feathers-Vuex is a first class integration of FeathersJS and Vuex. It implements many Redux best practices under the hood, eliminates a

Feathers Ecosystem 448 Nov 24, 2022
Vue LaunchDarkly plugin and routing utilities

Vue LaunchDarkly A simple wrapper around the js-client-sdk that provides observable feature flags, a ready state to ensure all feature flags are up to

Dash Hudson 25 Dec 19, 2022