If your contracts compiled and migrated successfully, below will show a stored value of 5 (by default).
\n
Try changing the value stored on line 71 of src/components/App.html.
\n
The stored value is: {storageValue}
\n
\n
\n
\n
\n\n\n\n"
9 | ],
10 | "names": [],
11 | "mappings": "AAmBE,SAAS,cAAC,CAAC,AACT,UAAU,CAAE,GAAG,AACjB,CAAC"
12 | }
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | svelte-box truffle base
8 |
9 |
10 |
11 |
14 |
15 |
16 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | ## SvelteJS Truffle Box
4 |
5 | A Truffle box using [SvelteJS](https://svelte.technology/) and [Rollup](https://rollupjs.org/).
6 |
7 | This box contains everything you need to start building a smart-contract app.
8 |
9 | ### Project Goal
10 |
11 | To provide the simplest, cleanest seed for building an Ethereum dapp using [Truffle](http://truffleframework.com/), with the minimum possible dependencies, meaning that beginners and pros a like have the most transparent possible method for developing [Ethereum](https://www.ethereum.org/) contracts.
12 |
13 | ### Truffle Box
14 |
15 | A [truffle box](http://truffleframework.com/boxes/) is a seed project for building a truffle dapp.
16 |
17 | ### Why Svelte?
18 |
19 | [Svelte](https://svelte.technology) was chosen as it is a rich, state-model based, ES6, component framework with very few dependencies, which is nothing more than html, javascript, and css. Once compiled via svelte, there are no clientside dependencies at all - simply vanilla JS.
20 |
21 | [Svelte](https://svelte.technology) is basically a simple DSL (domain specific language) for building a reactive, stateful, dependency-free web-application in pure javascript.
22 |
23 | Additionally, the [Svelte](https://svelte.technology) API is so simple and well-designed, you can learn the whole thing from scratch in less than an hour!
24 |
25 | ### Why Rollup?
26 |
27 | Originally this project used ParcelJS but sadly Parcel's support for Svelte is currently broken, and has been for a while. I've switched to RollupJS in order to upgrade to Svelte 3.
28 |
29 | Currently, we load web3 from UNPKG, since it appears to be borderline impossible to bundle successfully. If anybody wants to open a PR to bundle Web3, it would be greatly appreciated.
30 |
31 | ## Setting up
32 |
33 | 1. Install truffle and an ethereum client. For local development, try Ethereum TestRPC.
34 | ```javascript
35 | npm install -g truffle // Version 3.0.5+ required.
36 | npm install -g ganache-cli // Or the ganache GUI will work too.
37 | ```
38 |
39 | 2. Download box.
40 | ```javascript
41 | truffle unbox antony/svelte-box
42 | ```
43 |
44 | 4. Run an Ethereum RPC. For simplicity and development we will be using Ethereum TestRPC.
45 | ```javascript
46 | ganache-cli
47 | ```
48 |
49 | 7. Compile and migrate the contracts after authenticating your account on the blockchain (i.e. restoring from seed in MetaMask).
50 | ```javascript
51 | truffle compile
52 | truffle migrate
53 | ```
54 |
55 | You're ready to go!
56 |
57 | ## Usage
58 |
59 | Components are in `src/components/*.html`. Everything else is in the usual place [according to the docs](https://github.com/trufflesuite/truffle-init-default)
60 |
61 | Run the testrpc so that you have a blockchain to work with, and deploy your contracts:
62 |
63 | ```bash
64 | testrpc
65 | truffle deploy
66 | ```
67 |
68 | Log in to metamask by importing the HD Wallet that testrpc gave you, and do the same for one of the accounts by entering its private key. Then, run the dev task to have the code updated in realtime as you develop:
69 |
70 | ```bash
71 | truffle compile
72 | npm run dev
73 | ```
74 |
75 | ## Publishing
76 |
77 | To produce your production dApp, run the build task:
78 |
79 | ```bash
80 | npm run build
81 | ```
82 |
83 | This will publish your completed dApp to the folder `./dist`
84 |
85 | ## Testing
86 |
87 | Testing works much the same way as it does in any web-application, with an additional `truffle test` command for testing smart contracts.
88 |
89 | Be sure you've compiled your contracts before running the tests, or you'll get file not found errors.
90 |
91 | ```javascript
92 | npm run test:unit // for dApp tests
93 | npm run test:contract // for contract tests
94 | ```
95 |
96 | ## Releasing
97 |
98 | To build the application for production, use the build command. A production build will be in the `./dist` folder.
99 |
100 | ```javascript
101 | npm run build
102 | ```
103 |
104 | ## FAQ
105 |
106 | * __Why is there both a truffle.js file and a truffle-config.js file?__
107 |
108 | Truffle requires the truffle.js file be named truffle-config on Windows machines. Feel free to delete the file that doesn't correspond to your platform.
109 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte'
2 | import resolve from 'rollup-plugin-node-resolve'
3 | import commonjs from 'rollup-plugin-commonjs'
4 | import livereload from 'rollup-plugin-livereload'
5 | import { terser } from 'rollup-plugin-terser'
6 | import json from 'rollup-plugin-json'
7 | import postcss from 'rollup-plugin-postcss'
8 | import builtins from 'rollup-plugin-node-builtins'
9 | import globals from 'rollup-plugin-node-globals'
10 |
11 | const production = !process.env.ROLLUP_WATCH;
12 |
13 | export default {
14 | input: 'src/main.js',
15 | output: {
16 | sourcemap: true,
17 | format: 'iife',
18 | name: 'app',
19 | file: 'public/bundle.js'
20 | },
21 | plugins: [
22 | json(),
23 | postcss(),
24 | resolve({
25 | jsnext: true,
26 | main: true,
27 | browser: true,
28 | preferBuiltins: true,
29 | dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
30 | }),
31 | commonjs({
32 | }),
33 | svelte({
34 | dev: !production,
35 | css: css => {
36 | css.write('public/bundle.css')
37 | }
38 | }),
39 | builtins(),
40 | globals(),
41 | !production && livereload('public'),
42 | production && terser()
43 | ],
44 | watch: {
45 | clearScreen: false
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/scripts/watch.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const rollup = require('rollup')
4 | const config = require('../config/rollup.config')
5 | const ora = require('ora')
6 |
7 | const watcher = rollup.watch(config)
8 |
9 | const spinners = { }
10 |
11 | function compilationStart () {
12 | spinners.compilation = ora('Starting compilation').start()
13 | }
14 |
15 | function bundleStart () {
16 | spinners.bundle = ora('Compiling bundle').start()
17 | }
18 |
19 | function fatal (e) {
20 | spinners.bundle.fail()
21 | spinners.compilation.fail(`Compilation failed ${e.error.message}`)
22 | }
23 |
24 | function error (e) {
25 | spinners.bundle.warn(`Bundle compilation failed ${e.error.message}`)
26 | }
27 |
28 | function bundleEnd () {
29 | spinners.bundle.succeed('Bundle compilation finished')
30 | }
31 |
32 | function compilationEnd () {
33 | spinners.compilation.succeed('Compilation finished')
34 | }
35 |
36 | const eventMappings = {
37 | START: compilationStart,
38 | BUNDLE_START: bundleStart,
39 | FATAL: fatal,
40 | ERROR: error,
41 | BUNDLE_END: bundleEnd,
42 | END: compilationEnd
43 | }
44 |
45 | watcher.on('event', event => {
46 | const handler = eventMappings[event.code]
47 | return handler ? handler(event) : console.info(event)
48 | })
--------------------------------------------------------------------------------
/src/components/App.svelte:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
Truffle Box
5 |
Skeleton SvelteJS truffle box
6 |
7 |
8 |
9 |
10 |
Smart Contract Example
11 |
If your contracts compiled and migrated successfully, below will show a stored value of 5 (by default).
12 |
Try changing the value stored on line 71 of src/components/App.html.