Dapp using Meteor
Pages 181
- Home
- [Arabic] العربية
- [Chinese Simplified] Ethereum 白皮书
- [Chinese] Ethereum TOC
- [Chinese] Ethereum 白皮書
- [English] Patricia Tree
- [English] RLP
- [English] White Paper
- [French] Ethereum TOC
- [German] Clearinghaus
- [German] Ethereum TOC
- [German] RLP
- [German] White Paper
- [Indonesian] Ethereum akan naik karena teknologi terus dikembangkan dan ditingkatkan
- [Italian] Ethereum TOC
- [Italian] Impostare il proprio ambiente di sviluppo Ethereum
- [Italian] Introduzione allo sviluppo su Ethereum
- [Italian] Libro Bianco
- [Japanese] Ethereum Development Tutorial
- [Japanese] Liscence
- [Japanese] Cryptocurrency Current Problems
- [Japanese] Design Rationale
- [Japanese] Ethereum TOC
- [Japanese] Ethereum Wire Protocol
- [Japanese] HPOC_2015
- [Japanese] Javascript API
- [Japanese] libp2p whitepaper
- [Japanese] Meteorを使ってDappを作ろう
- [Japanese] Patricia Tree
- [Japanese] RLP
- [Japanese] Whisper
- [Japanese] Whisper PoC 2 Protocol Spec
- [Japanese] White Paper
- [Japanese] ÐΞVp2p Wire Protocol
- [Korean] White Paper
- [Persian] Ethereum TOC
- [Persian] White Paper
- [Portuguese] White Paper
- [Romanian] Cuprins
- [Romanian] Limbajul de programare Serpent
- [Romanian] Patricia Tree
- [Romanian] RLP
- [Romanian] White Paper
- [Romanian] Wire Protocol
- [Russian] Руководство по Solidity
- [Spanish] Ethereum TOC
- [Spanish] White Paper.md
- [中文] RLP
- [中文] Serpent指南
- [中文] 以太坊Wiki目录
- [中文] 以太坊开发计划
- [中文] 以太坊术语表
- [中文] 以太坊白皮书
- [中文] 网络状态
- Adaptive Message IDs
- Adaptive Peer Time
- Atar Gold
- Bad Block Reporting
- Bad Chain Canary
- Benchmarks
- Block Protocol 2.0
- Blockchain import and export instructions
- Brain Wallet
- Bugs
- Byzantium Hard Fork changes
- Casper Proof of Stake compendium
- CC0 license
- Chain Fibers Redux
- Client Version Strings
- Clients
- Consortium Chain Development
- Contract
- Contract metadata
- Contract Metadata Docs (NatSpec, ABI)
- Dagger Hashimoto
- Dapp Developer Resources
- Dapp using Meteor
- Decentralized apps (dapps)
- Default Extra Data Standard
- Design Rationale
- Deterministic_Wallet_Spec
- Distributed Preimage Archive
- enode url format
- ERC 735: Claim Holder Registry vs. in contract
- Ethash
- Ethash C API
- Ethash DAG
- Ethash DAG Disk Storage Format
- Ethash Design Rationale
- Ethereum Chain Spec Format
- Ethereum Contract ABI
- Ethereum Development Tutorial
- Ethereum Introduction
- Ethereum Natural Specification Format
- Ethereum Sharding Research Compendium
- Ethereum Virtual Machine (EVM) Awesome List
- Ethereum White Paper
- Ethereum Wire Protocol
- Exchange Integration
- eπ Programme
- FAQs
- Geth Dapp loading proposal
- Getting Ether
- Getting Ether: further info
- Gitter Channels
- Glossary
- Home in Arabic
- HPOC_2015
- ICAP: Inter exchange Client Address Protocol
- IPv6
- JavaScript API
- JSON RPC
- JSON RPC Error Codes Improvement Proposal
- Kademlia Peer Selection
- libp2p Whitepaper
- Licensing
- Light client protocol
- Major issues resulting in lost or stuck funds
- Middleware and Dapp Project Ideas
- Mining
- Mist Troubleshooting Guide
- Mix Features
- Mix improvement proposal
- Mix: The DApp IDE
- Morden
- NatSpec Determination
- Natspec Example
- Network Status
- newBlockFilter Improvement Proposal
- Node discovery protocol
- Open positions & Schemes
- Outdated: Poll for token proposal EIP 20
- Outdated: Proposal: Reversion Notification
- Outdated: Proposal: Transaction Proxy Hooks
- Parallel Block Downloads
- Patricia Tree
- Problems
- Programming languages intro
- Proof of Stake FAQ
- R&D
- Raspberry Pi instructions
- Registrar ABI
- Releases
- RLP
- RPC Testing
- Safety
- Security Categorization
- Security Issue Process
- Serpent
- Sharding FAQ
- Sharding introduction and implementations
- Solidity
- Solidity Changelog
- Solidity Collections
- Solidity Features
- Solidity Glossary
- Solidity standard library
- Solidity Tutorial
- Solidity, Docs and ABI
- Standardized_Contract_APIs
- Subtleties
- Swarm Hash
- The Solidity Programming Language
- URL Hint Protocol
- Useful Ðapp Patterns
- web.js 0.9
- Web3 Secret Storage Definition
- web3js api reference
- What is Ethereum
- Whisper
- Whisper Overview
- Whisper pages
- Whisper PoC 2 Protocol Spec
- Whisper PoC 2 Wire Protocol
- Whisper Wire Protocol
- White Paper
- Wishlist
- ÐApp Development
- ÐΞV Technologies
- ÐΞVp2p Wire Protocol
- Руководство по Solidity
- Show 166 more pages…
Basics
- Home
- Wiki for (old) website (still a good introduction)
- Ethereum Introduction
- Ethereum Whitepaper
- Design Rationale
- EVM intro: Ethereum Yellow Paper, Beige Paper and Py-EVM.
- Getting Ether
- Uses: DAOs and dapps
- Releases
- FAQs
- Proof of Stake FAQ
- Sharding introduction and implementations
- Sharding phase 1 spec
- Sharding FAQ
- Ethereum Research Sharding Compendium
- Casper Proof-of-Stake compendium.
Ethereum Virtual Machine (EVM)
- Geth (Go)
- Parity (Rust)
- cpp-ethereum (C++)
- pyethapp (Python)
- py-evm (Python, has a sharding implementation under development)
- ethereumjs-vm repo (Javascript, not a wiki)
- eWASM, with Hera, an implementation in C++; evm2wasm, an implemenation in Web Assembly; and an implementation in Javascript
- Sharding introduction and implementations
- Harmony/ethereumj (Java)
- Safety
- ÐApp Developer Resources
- JavaScript API
- JSON RPC API
- Solidity
- Solidity Glossary
- Solidity Features
- Solidity Collections
- Solidity Cheat-sheet
- Useful Ðapp Patterns
- Standardized Contract APIs
- ÐApp using Meteor
- Ethereum development tutorial
- Mix Tutorial
- Mix Features
- Vyper
- Serpent
- LLL
- Mutan
Infrastructure
- Chain Spec Format
- Inter-exchange Client Address Protocol
- URL Hint Protocol
- NatSpec Determination
- Network Status
- Raspberry Pi
- Exchange Integration
- Mining
- Licensing
- Consortium Chain Development
- RLP Encoding
- Node Discovery Protocol
- ÐΞVp2p Wire Protocol
- ÐΞVp2p Whitepaper (WiP)
- Web3 Secret Storage
- libp2p
Ethereum Technologies
- Patricia Tree
- Wire protocol
- Light client protocol
- Subtleties
- Solidity Documentation
- NatSpec Format
- Contract ABI
- Bad Block Reporting
- Bad Chain Canary
Ethash/Dashimoto
Misc
Clone this wiki locally
This tutorial will show you how to setup a Meteor app to be used as a Ðapp and probably answer a few questions on why Meteor should be used.
- Create your Ðapp
- Start your Ðapp
- Connect your Ðapp
- Run your Ðapp
- Add Ðapp styles
- Using ethereum:elements
- Ðapp code structure
- Bundle your Ðapp
- Submit your Ðapp
FAQ
Isn't Meteor a full stack framework, how does that fit into Ðapp development
True, Meteor is a full stack framework and its main improvement is realtime web applications, but Meteor is also the first framework (i know of), which fully embraced single page app (SPA) development and provided all necessary tools.
5 reasons why Meteor is a perfect fit:
- Its purely written in JS and has all the tools a SPA needs (Templating engine, Model, on-the-fly compiling, bundling)
- You get a development environment, which has live reload, CSS injection and support for many pre-compilers (LESS, Coffeescript, etc) out of the box
- You can get all frontend code as single
index.htmlwith onejsandcssfile plus your assets, using meteor-build-client. You can then host it everywhere or simple run theindex.htmlitself or distribute it later on swarm. - It embraces full reactivity, which make building consistent interface much easier (similar to angular.js
$scopeor binding) - It has a great model called Minimongo, which gives you a mongoDB like interface for a reactive in-memory database, which can also be auto-persisted to localstorage or indexedDB
Do I need to host my Ðapp on a server?
No, using meteor-build-client you can get all the static assets of your Ðapp to run without a server, though if you use a router like iron- or flow-router, you need to use hash (index.html#!/mypath) routes instead of clean HTML5 pushstate routes.
Create your Ðapp
Install Meteor if don't have already:
$ curl https://install.meteor.com/ | shThen create an app:
$ meteor create myDapp
$ cd myDappNext add the web3 package:
$ meteor add ethereum:web3I recommend also to add the following packages:
- ethereum:dapp-styles - The LESS/CSS framework which gives your dapp a nice Mist-consistent look.
-
ethereum:tools - This package gives you the
EthToolsobject with a set of formatting an conversion functions and template helpers for ether. - ethereum:elements - A set of interface elements specifically made for ethereum.
-
ethereum:accounts - Gives you the reactive
EthAccountscollection with all current available ethereum accounts, where balances will be automatically updated. -
ethereum:blocks - Gives you the reactive
EthBlockscollection with the latest 50 blocks. To get the lastest block useEthBlocks.latest(It will also have the latest default gasPrice) -
frozeman:template-var - Gives you the
TemplateVarobject, that allows you to set reactive variables, which are template instance specific. See the readme for more. - frozeman:persistent-minimongo2 - Allows you to auto persist your minimongo collection in local storage
Start your Ðapp
A short excursion into Meteors folder structure
Meteor doesn't force you to have a specific folder structure, though some folders have specific meaning and will be treated differently when bundling/running your application.
Folders with specific treatment
-
client- files in a folder calledclientwill only be loaded by the client part of your app and as we are building a Ðapp, that's where most of our files go. -
lib- files in folders calledlibwill load before other files in the same folder. This is an ideal place your init files, libraries, or ethereum specific files. -
public- a folder calledpubliccontains assets meteor will make available on the root of your webserver (or later bundled Ðapp) - There are a few more specific folders like
server,tests,packages, etc. If you want to get to know them take a look at the Meteor docs
So to build a Ðapp we ideally create the following folder structure in our myDapp folder:
- myDapp
- client
- lib
- myDapp.html
- myDapp.js
- myDapp.css
- public
Note The community provides also Meteor Ðapp Boilerplates like this one from Nick Dodson: https://github.com/SilentCicero/meteor-dapp-boilerplate
Connect your Ðapp
To connect our dapp we need to start geth with the right CORS headers in another terminal:
$ geth --rpc --rpccorsdomain "http://localhost:3000"We also need to set the provider. Ideally we create a file in our lib folder called init.js and add the following line:
if(typeof web3 === 'undefined')
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));Run your Ðapp
Now we can run our Ðapp by simply running:
$ meteorIf we go to http://localhost:3000, we should see a website appear and if we open the browser console we can use the web3 object to query the geth node:
> web3.eth.accounts
['0xfff2b43a7433ddf50bb82227ed519cd6b142d382']Add Ðapp styles
If you want your Ðapp to nicely fit later into Mist and have follow the official look use the dapp-styles css css/less framework.
Note that they are under heavy development and the class names and elements may change.
To add it simple add the following packages to your Ðapp:
$ meteor add less
$ meteor add ethereum:dapp-stylesNow rename you myDapp.css to myDapp.less and add the following line inside:
// libs
@import '{ethereum:dapp-styles}/dapp-styles.less';Now you can use all dapp-styles classes and also overwrite all variables of the framework. You can find them in the repo. Overwrite them by copying them to your myDapp.less file and set different values.
Using ethereum packages
To make your life as a Ðapp developer easier we provide some packages that help you build Ðapps faster.
If you add the recommended packages above you should have the ethereum:tools, ethereum:accounts and ethereum:blocks packages available.
These 3 packages give you the EthTools, EthAccounts and Ethblocks objects, which give you formatter functions, a collection with the accounts from web3.eth.accounts (with auto updated balance) and a collection of the last 50 blocks.
Most of these functions are reactive so they should make building interfaces a breeze.
Example usage
If you look into you myDapp.html you will find the hello template.
Just add a helper called {{currentBlock}} some where between the <template name="hello">..</template> tags.
Now open the myDapp.js and add after the counter() {..} the currentBlock helper:
Template.elements.helpers({
counter() {
...
},
currentBlock() {
return EthBlocks.latest.number;
}
});Then initialize EthBlocks by adding EthBlocks.init(); after this.counter = new ReactiveVar(0);
If you now check your Ðapp in the browser you should see the latest block number, which will increase once you mine.
For more examples please checkout the packages readmes and the demo (source) for more.
Ðapp code structure
This tutorial won't go into building apps with Meteor. For this please refer to the Meteor's tutorials, A list of good resources, EventMinded (payed tutorials) or books like Building Single-page Web Apps with Meteor or Discover Meteor.
TODO Short:
- put ethereum related stuff into
client/lib/ethereum/somefile.js - use
myCollection.observe({added: func, changed: func, removed: func})to communicate to ethereum, keep ethereum logic out of your app as much as possible. This way you just write and read from your reactive collections and the observe functions will handle the rest (e.g. sendTransactions) - Filters etc will add logs etc to your collections. So you keep all the callback mess out of your app logic.
For an example see the Ethereum-Wallet.
Bundle your Ðapp
To bundle your Ðapp into a local standalone file use meteor-build-client:
$ npm install -g meteor-build-client
$ cd myDapp
$ meteor-build-client ../build --path ""This will put your Ðapps static files into the build folder, above your myDapp folder.
The last option --path will make the linking of all files relative, allowing you to start the app by simply clicking the build/index.html.
Be aware that when running your app on the file:// protocol, you won't be able to use client side routing, due to web security. Later in mist you will be able to use client side routing, as dapps are served over the eth:// protocol.
In the future you will be able to simply upload your Ðapp on swarm.
Submit your Ðapp
To get early traffic to your Ðapp, you can submit your Ðapp to Dapp Insight. This is a most popular Dapp analytics tool which listing all the running Dapps in the world.