Beruflich Dokumente
Kultur Dokumente
scratch because it helps you build your dapp from scratch. (Github Repo)
Options:
Commands:
/*
* To use FeverContract just import it into your project:
*/
/*
* Have Fun : )
*/
. . .
The Tutorial
In this tutorial we’ll be using:
• npm
• Tru e
. . .
contract FeverContract {
uint8 temperature;
function FeverContract() {
temperature = 98;
}
Here you can see we have all the aspects of the contract described earlier, a
temperature , transactional functions to increaseTemp() and to
decreaseTemp() as well as constant functions to getTemperature() and
check whether the contract hasFever() or not.
Now we can run tru e’s test network, compile and deploy the contract.
$ truffle develop
truffle(develop)> deploy
. . .
The program will look for your ABI and then check your package.json for
the necessary dependencies. Once those have been installed it will create a
new directory called dapp-scratch-wrapper with your new DappScratch
module inside.
UPDATE: dapp-scratch has been updated so some path names in this image are di erent from what you’ll encounter
The rst thing you want to do is go back to your terminal window running
your tru e test network and look for the address of the deployed
FeverContract.
Copy this address and add it to your new FeverContract module at ./dapp-
Now we can import the module into our app and start using it.
. . .
<template>
<div id="app">
<div id="temp" v-text="temp"></div>
<div @click="checkTemp()" class='emoji' v-text="emoji"></div>
<div>
<span class='emoji' @click="decreaseTemp()">❄ </span>
<span class='emoji' @click="increaseTemp()"> </span>
</div>
</div>
</template>
<script>
const FeverContract = require('../dapp-module/FeverContract')
let feverContract = new FeverContract()
feverContract.helloWorld()
export default {
name: 'app',
...
Now we can add methods that hook up to our new template and allow us to
access our contract via the module. We should also add a data state that
re ects the current status of our contract.
export default {
name: 'app',
data () {
return {
hasFever: false,
temp: 98
}
},
computed: {
emoji () {
return this.temp > 110 || this.temp < 95 ? ' ' :
(this.hasFever ? ' ' : ' ')
}
},
methods: {
checkTemp () {
return feverContract.hasFever().then((hasFever) => {
this.hasFever = hasFever
return feverContract.getTemperature().then((temp) => {
this.temp = temp
})
})
},
increaseTemp () {
return feverContract.increaseTemp().then((temp) => {
return this.checkTemp()
})
},
decreaseTemp () {
return feverContract.decreaseTemp().then((temp) => {
return this.checkTemp()
})
}
}
}
<style>
body {
background-color: white;
}
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
#temp {
position: absolute;
top: 10px;
right: 10px;
font-size:50px;
}
#temp:after {
content: 'º';
}
.emoji {
font-size:120px;
cursor: pointer;
}
</style>
And we’ve got ourselves an App! Let’s run npm run dev to start the
development environment and try interacting with it at
http://localhost:8080 — Error, right? That’s cause we still need some kind
of provider to interact with the blockchain
. . .
At this point you’ve got the choice of interacting with the app via MetaMask
or the Aeternity Identity Manager. I’m going to go through the directions to
use the Identity Manager because it’s new and o ers a mobile ready
alternative to MetaMask (Full disclosure: I’ve been consulting for their app
team), but the steps are basically the same for both options:
2. Import the tru e test account using the mnemonic phrase from earlier
Let’s get started using the identity manager by importing the mnemonic
phrase at http://identity.aepps.com. Use the “Recover with Seed Phrase”
option and paste in the phrase generated in the command line by tru e:
candy maple cake sugar pudding cream honey rich smooth crumble
sweet treat
Afterwards, set a personal password and you’ll see your wallet with all you
currently available addresses.
Now you can close the wallet view and add the new app to the Home screen.
Just use the development address http://localhost:8080 and name it Dapp
Scratch Fever.
When launched, Identity Manager will make an iframe that contains your
app. This way the app can be visited on mobile devices
Now we can nally open the app and raise the temp
Or you can cool our guy down again to a better living standard ❄
. . .
Conclusion
In total we’ve covered:
. . .
Don’t forget to check out the repo and add your own best practices for
interacting with Solidity contracts from decentralized applications. This
tutorial is also available on github here ✌
283 1
Responses
Write a response…
Never miss a story from codeburst, when you sign up for Medium.
GET UPDATES
Learn more