Difference between revisions of "Setting up Truffle"

From rbachwiki
Jump to navigation Jump to search
(Created page with "=Setting up Truffle for your project= # go into your project Directory truffle init ''' You need to create your smart contracts in the ''contracts folder'' '''")
 
 
(8 intermediate revisions by the same user not shown)
Line 5: Line 5:


''' You need to create your smart contracts in the ''contracts folder'' '''
''' You need to create your smart contracts in the ''contracts folder'' '''
''' Then you need to create a file int eh migrations folder to process your contract'''
Filename: 2_deploy_contracts.js
var Greetings = artifacts.require("./Greetings.sol");
module.exports = function(deployer){
    deployer.deploy(Greetings);
};
== Now to deploy the contract ==
Truffle has a build in ganache server and the accounts are the same as ganache
'''Start the development mode of truffle'''
truffle develop
Open a new terminal window to see the logs
Go into the project directory
truffle develop --log
'''Now to build and deploy the contract '''
switch back to the develop console
migrate --compile-all --reset
'''To interact with the contract, use the develop console'''
Greetings.address
web3.eth.accounts
'''before we can call functions of our contract we have to create an instance of it and store it in a local variable'''
Greetings.deployed().then(function(instance){app = instance;})
It will returned ''undefined''
app
app.getGreetings()
app.setGreetings("Robert", {from: web3.eth.accounts[0]})
app.getGretings()
Exit the development console
.exit
Ctrl C to exit the log console
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Solidity_ethereum_Language|Category]]==

Latest revision as of 23:04, 13 March 2018

Setting up Truffle for your project

  1. go into your project Directory
truffle init

You need to create your smart contracts in the contracts folder Then you need to create a file int eh migrations folder to process your contract Filename: 2_deploy_contracts.js

var Greetings = artifacts.require("./Greetings.sol");
module.exports = function(deployer){
   deployer.deploy(Greetings);
};

Now to deploy the contract

Truffle has a build in ganache server and the accounts are the same as ganache Start the development mode of truffle

truffle develop

Open a new terminal window to see the logs Go into the project directory

truffle develop --log

Now to build and deploy the contract switch back to the develop console

migrate --compile-all --reset

To interact with the contract, use the develop console

Greetings.address
web3.eth.accounts

before we can call functions of our contract we have to create an instance of it and store it in a local variable

Greetings.deployed().then(function(instance){app = instance;})

It will returned undefined

app
app.getGreetings()
app.setGreetings("Robert", {from: web3.eth.accounts[0]})
app.getGretings()

Exit the development console

.exit

Ctrl C to exit the log console


Back To Top- Home - Category