├── src ├── index.css ├── assets │ └── logo.png ├── composer.js ├── components │ ├── ApplicationLog.vue │ ├── MoralisLogin.vue │ ├── AvatarList.vue │ └── AvatarGenerator.vue ├── moralis.js ├── main.js └── App.vue ├── public ├── favicon.ico └── index.html ├── babel.config.js ├── postcss.config.js ├── .env ├── tailwind.config.js ├── .gitignore ├── vue.config.js ├── hardhat.config.js ├── LICENSE ├── package.json └── README.md /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alkavan/moralis-vue-template/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alkavan/moralis-vue-template/HEAD/src/assets/logo.png -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | VUE_APP_MORALIS_APP_ID="APP_ID" 2 | VUE_APP_MORALIS_KEY="APP_KEY" 3 | VUE_APP_MOLARIS_SERVER_URL="https://server-url:2053/server" 4 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | content: [ 3 | './src/**/*.{vue,js,ts,jsx,tsx}', 4 | ], 5 | theme: { 6 | container: { 7 | center: true, 8 | }, 9 | extend: {}, 10 | }, 11 | variants: { 12 | extend: {}, 13 | }, 14 | plugins: [], 15 | } 16 | -------------------------------------------------------------------------------- /src/composer.js: -------------------------------------------------------------------------------- 1 | const MoralisCompose = (function(moralis) { 2 | class Avatar extends moralis.Object { 3 | constructor() { 4 | super('Avatar'); 5 | } 6 | } 7 | 8 | return { 9 | Avatar: Avatar 10 | } 11 | }); 12 | 13 | export default MoralisCompose; 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | const { defineConfig } = require('@vue/cli-service') 2 | const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); 3 | module.exports = defineConfig({ 4 | transpileDependencies: true, 5 | configureWebpack: { 6 | plugins: [new NodePolyfillPlugin()], 7 | optimization: { 8 | splitChunks: { 9 | chunks: "all", 10 | }, 11 | }, 12 | }, 13 | }); 14 | -------------------------------------------------------------------------------- /src/components/ApplicationLog.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 22 | 23 | 26 | -------------------------------------------------------------------------------- /hardhat.config.js: -------------------------------------------------------------------------------- 1 | require("@nomiclabs/hardhat-waffle"); 2 | 3 | // This is a sample Hardhat task. To learn how to create your own go to 4 | // https://hardhat.org/guides/create-task.html 5 | task("accounts", "Prints the list of accounts", async () => { 6 | const accounts = await ethers.getSigners(); 7 | 8 | for (const account of accounts) { 9 | console.log(account.address); 10 | } 11 | }); 12 | 13 | // You need to export an object to set up your config 14 | // Go to https://hardhat.org/config/ to learn more 15 | 16 | /** 17 | * @type import('hardhat/config').HardhatUserConfig 18 | */ 19 | module.exports = { 20 | solidity: "0.7.3", 21 | }; 22 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/moralis.js: -------------------------------------------------------------------------------- 1 | const MORALIS_APP_ID = process.env.VUE_APP_MORALIS_APP_ID; 2 | const MORALIS_KEY = process.env.VUE_APP_MORALIS_KEY; 3 | const MOLARIS_SERVER_URL = process.env.VUE_APP_MOLARIS_SERVER_URL; 4 | 5 | const MoralisFactory = (function() { 6 | const Moralis = require('moralis'); 7 | 8 | function MoralisInstance(applicationId, javascriptKey, url) { 9 | Moralis.initialize( 10 | applicationId, 11 | javascriptKey, 12 | ); 13 | 14 | Moralis.serverURL = url; 15 | 16 | return Moralis; 17 | } 18 | 19 | let instance = null; 20 | 21 | return { 22 | getInstance: function() { 23 | if (instance == null) { 24 | instance = MoralisInstance(MORALIS_APP_ID, MORALIS_KEY, MOLARIS_SERVER_URL); 25 | instance.constructor = null; 26 | } 27 | return instance; 28 | }, 29 | }; 30 | })(); 31 | 32 | export default MoralisFactory; 33 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import {createApp} from 'vue' 2 | import App from './App.vue' 3 | import mitt from 'mitt'; 4 | import './index.css' 5 | 6 | import MoralisFactory from './moralis' 7 | import MoralisCompose from './composer' 8 | 9 | import Avatars from '@dicebear/avatars'; 10 | import SpriteCollection from '@dicebear/avatars-bottts-sprites'; 11 | 12 | const app = createApp(App) 13 | 14 | app.provide('event-bus', mitt()) 15 | app.provide('moralis', MoralisFactory.getInstance()) 16 | 17 | const avatars = new Avatars(SpriteCollection); 18 | app.provide('avatars', avatars) 19 | 20 | // Here we provide a way for all components to access moralis 21 | app.mixin({ 22 | inject: { 23 | moralis: { 24 | from: 'moralis' 25 | }, 26 | emitter: { 27 | from: 'event-bus' 28 | }, 29 | }, 30 | methods: { 31 | moralisCompose(molaris) { 32 | return MoralisCompose(molaris); 33 | } 34 | } 35 | }); 36 | 37 | app.mount('#app'); 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2021 Igal Alkon 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 | OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 37 | 38 | 44 | -------------------------------------------------------------------------------- /src/components/MoralisLogin.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 47 | 48 | 51 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "moralis-vue-template", 3 | "version": "1.1.0", 4 | "private": false, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint", 9 | "hardhat-node": "npx hardhat node" 10 | }, 11 | "dependencies": { 12 | "core-js": "^3.8.3", 13 | "jquery": "^3.6.0", 14 | "mitt": "^2.1.0", 15 | "moralis": "^0.0.184", 16 | "@walletconnect/web3-provider": "^1.8.0", 17 | "autoprefixer": "^9.8", 18 | "postcss": "^8.4", 19 | "tailwindcss": "^3.1", 20 | "vue": "^3.2", 21 | "@dicebear/avatars": "^4.5.4", 22 | "@dicebear/avatars-bottts-sprites": "^4.5.4" 23 | }, 24 | "devDependencies": { 25 | "@babel/core": "^7.12", 26 | "@babel/eslint-parser": "^7.12", 27 | "@nomiclabs/hardhat-ethers": "^2.1", 28 | "@nomiclabs/hardhat-waffle": "^2.0", 29 | "@vue/cli-plugin-babel": "^5.0", 30 | "@vue/cli-plugin-eslint": "^5.0", 31 | "@vue/cli-service": "^5.0", 32 | "chai": "^4.3.4", 33 | "eslint": "^7.32.0", 34 | "eslint-plugin-vue": "^8.0", 35 | "ethereum-waffle": "^3.3", 36 | "ethers": "^5.7", 37 | "node-polyfill-webpack-plugin": "^2.0", 38 | "hardhat": "^2.10" 39 | }, 40 | "eslintConfig": { 41 | "root": true, 42 | "env": { 43 | "node": true 44 | }, 45 | "extends": [ 46 | "plugin:vue/vue3-essential", 47 | "eslint:recommended" 48 | ], 49 | "parserOptions": { 50 | "parser": "@babel/eslint-parser" 51 | }, 52 | "rules": {} 53 | }, 54 | "browserslist": [ 55 | "> 1%", 56 | "last 2 versions", 57 | "not dead" 58 | ] 59 | } 60 | -------------------------------------------------------------------------------- /src/components/AvatarList.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 62 | 63 | 66 | -------------------------------------------------------------------------------- /src/components/AvatarGenerator.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 82 | 83 | 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Moralis Application Template for Vue.js and TailwindCSS 2 | 3 | This is a basic [Vue.js](https://vuejs.org/) v3 template 4 | for the [Moralis](https://moralis.io/) web3 application development platform. 5 | 6 | ## Components 7 | This project utilizes libraries and tools that are quite useful 8 | when developing web and blockchain applications. 9 | 10 | * [Moralis](https://moralis.io/) v0.0.184 11 | * [Hardhat](https://hardhat.org/) used a local development environment for Ethereum. 12 | * [Vue.js](https://vuejs.org/) v3.2 used as frontend application framework. 13 | * [tailwindcss](https://tailwindcss.com/) v3.1 used as CSS framework. 14 | * [mitt](https://www.npmjs.com/package/mitt) is used a global event bus for Vue. 15 | 16 | **This template was built and tested on Node v16** 17 | 18 | ## Update v1.1 (Aug 25, 2022) 19 | * Updated packages and frameworks: 20 | * Moralis to v0.0.184 21 | * Vue to v3.2 22 | * Tailwind to v3.1 23 | * Updated related packages and dependencies. 24 | * Updated `vue.config.js` and `tailwind.config.js` for new versions. 25 | 26 | ## Install Instruction 27 | Install packages 28 | ``` 29 | npm install 30 | ``` 31 | 32 | To run the Hardhat development server in node mode: 33 | ``` 34 | npm run hardhat-node 35 | ``` 36 | 37 | To start the web application: 38 | ``` 39 | npm run serve 40 | ``` 41 | 42 | The `dotenv` package is used to load environment variables from `.env` files. 43 | The package comes as a dependency of Vue. You don't want to commit your secret variables 44 | by mistake, so I recommend doing this: 45 | ``` 46 | cp .env .env.local 47 | ``` 48 | Then update your variables in `.env.local` it has higher priority than the `.env` file. 49 | The `.env.local` file will also be ignored by git. 50 | 51 | The moralis instance in injected into the Vue application globally using `mixin()`. 52 | So it will be available for all components automatically and accessed with `this.moralis`. 53 | 54 | The `mitt` based global event bus is also available in similar manner via `this.emitter`. 55 | 56 | Remember that Vue also have its own event system, 57 | and you should use the global event bus only for scenarios when two unrelated 58 | components need to share state, or for non-vue objects. 59 | 60 | On another note, you might be asking wtf is `composer.js`? 61 | well that's just a place to store moralis object definitions outside the Vue application. 62 | I don't feel comfortable placing this logic inside the components files. 63 | However, I'm also not very happy with the current situation, 64 | and you're welcome to make suggestions via pull requests on github. 65 | 66 | I included `MoralisLogin` component as example for login/logout logic. 67 | This package is published under the [MIT](https://en.wikipedia.org/wiki/MIT_License) license, 68 | however contribution of more Moralis based components is more than welcome! 69 | 70 | The `@dicebear/avatars` and `@dicebear/avatars-bottts-sprites` packages are used only for this example 71 | application and are probably not really needed for you. You can just remove them: 72 | ``` 73 | npm remove @dicebear/avatars @dicebear/avatars-bottts-sprites 74 | ``` 75 | 76 | Also, the `AvatarGenerator.vue`, `AvatarList.vue` component files and their usage in `App.vue`. 77 | 78 | --------------------------------------------------------------------------------