Using Truffle to Create and Deploy Smart Contracts

$ truffle
Truffle v3.2.1 - a development framework for Ethereum
Usage: truffle <command> [options]Commands:
init Initialize new Ethereum project with example contracts and tests
...
$ mkdir storage_smart_contract_example
$ cd storage_smart_contract_example
$ truffle init
pragma solidity ^0.4.8;contract Storage {
uint256 storedData;
function set(uint256 data) {
storedData = data;
}
function get() constant returns (uint256) {
return storedData;
}
}
var Storage = artifacts.require("./Storage.sol");module.exports = function(deployer) {
deployer.deploy(Storage);
};
$ npm install -g ethereumjs-testrpc$ testrpcEthereumJS TestRPC v3.0.3Available Accounts
==================
...
$ truffle compile
$ truffle migrate
$ truffle consoletruffle(development)> Storage.deployed().then(instance => instance.get.call()).then(result => storeData = result){ [String: '0'] s: 1, e: 0, c: [ 0 ] }truffle(development)> storeData.toString()
'0'
truffle(development)> Storage.deployed().then(instance => instance.set.sendTransaction(42)).then(result => newStorageData = result)
'0xc5e2f9c9da4cf9f563c8e59073d5b6ca9458f112a6dcfc14aaea7c16a99422d4'
truffle(development)> Storage.deployed().then(instance => instance.get.call()).then(result => storeData = result)
{ [String: '42'] s: 1, e: 1, c: [ 42 ] }
truffle(development)> storeData.toString()
'42'

--

--

A curious mind, joie de vivre practitioner

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gustavo (Gus) Guimaraes

Gustavo (Gus) Guimaraes

A curious mind, joie de vivre practitioner