February 6, 2026

Building a Guestbook dApp with Vue.js and Truffle – James Kehoe

Building a Guestbook dApp with Vue.js and Truffle – James Kehoe

Open up truffle-config.js and modify module.exports to tell Truffle to place its JSON build output inside the src folder where the front end can access it.

Inside the contracts folder (in the project root, not src/contracts), create a new file called Guestbook.sol and create the contract.

The first line declares which version of the Solidity compiler this contract should use. For our purposes, we’ll use the same range of versions as the contract created by running truffle init.

The next block is the contract. First we make an event to fire whenever a signature is added. Then we make an array to hold the names. Next, a method to push a name to the array and emit the event to anyone that’s listening. Finally, we create a method that returns the list of names.

The contract is ready to deploy! But first we need to create a migration to tell Truffle about our new contract. Inside the migrations folder, create a new migration file called 2_deploy_guestbook.js. Add the following contents:

Back inside your console in the project root directory, initialize the Truffle dev console.

You’ll be rewarded with your own personal blockchain! There’s a list of addresses and private keys, as well as the mnemonic you’ll need to connect to this wallet elsewhere. You’ll notice your console has changed to truffle(develop)>. To both compile and migrate your contracts with one fell swoop, simply run:

to start with a fresh slate every time you migrate and ensure changes to your contracts propagate.

If all goes well, you should see a bunch of data related to the successful deployment of the contact to the dev blockchain.

npm install @drizzle/vue-plugin
import Guestbook from "@/contracts/Guestbook.json";const options = 
},
// The contracts to monitor
contracts: [Guestbook],
events: ,
polls:
};
export default options;
import Vue from "vue"
import App from "./App.vue"
import store from "./store"
import drizzleVuePlugin from "@drizzle/vue-plugin"
import drizzleOptions from "./drizzleOptions"
Vue.config.productionTip = falseVue.use(drizzleVuePlugin, )new Vue().$mount("#app")
<template>
<div v-if="isDrizzleInitialized" id="app">
<h1>Sign the Guestbook</h1>
<drizzle-contract-form
contractName="Guestbook"
method="signBook"
:placeholders="['Name']"
/>
<h2>Guests:</h2>
<ul v-if="getNames">
<li v-for="(name, i) in getNames" :key="i">}</li>
</ul>
</div>
<div v-else>
Loading application...
</div>
</template>
<script>
import from "vuex"
export default );
if (data === "loading") return false;
return data
},
utils()
},
created() )
}
}
</script>
npm run serve

Published at Sun, 29 Sep 2019 16:15:12 +0000

{flickr|100|campaign}

Previous Article

Aegean for Android will have different options to mix bitcoins:

Next Article

U.S. Denies China Company De-Listing. But The Writing is On The Wall

You might be interested in …

On Blockchain Spam – Andrew Stone

On Blockchain Spam – Andrew Stone

On Blockchain Spam – Andrew Stone The blockchain spam debate is rearing up again with similar arguments and division. To come to some clarity on the subject it is first important to understand that participants […]