34 votes
Accepted

In the truffle console, how to set and get current account?

In truffle console: var accounts; // in web front-end, use an onload listener and similar to this manual flow ... web3.eth.getAccounts(function(err,res) { accounts = res; }); var account1 = ...
Rob Hitchens's user avatar
  • 55.2k
32 votes

Oracle (oraclize.it) with Truffle and Testrpc

It is very possible to use the Oraclize service with testrpc alongside truffle. Firstly, you need to follow the naming convention of contract filenames in truffle. As per their docs: Truffle ...
DenisM's user avatar
  • 1,021
28 votes
Accepted

Truffle migrate fails

This seems to occur if you're trying to deploy contract A that depends on contract B before contract B has actually finished deploying. You probably have something like this: module.exports = ...
Mike Shultz's user avatar
  • 1,212
24 votes
Accepted

How to pass constructor parameters to a contract using Truffle?

In Truffle, constructor params go in /migrations. So, something like: deployer.deploy(User, "foo"); User.deployed() will be a User contract that was deployed with _name="foo"
Rob Hitchens's user avatar
  • 55.2k
24 votes
Accepted

Problem with Truffle Console: Cannot read property 'call' of undefined

If you are running the latest version of Truffle (v.3.x), the way to call a function or variable in your contract has evolved a little bit according to the Upgrading documentation In Truffle 2.0, ...
Greg Jeanmart's user avatar
23 votes
Accepted

How do Enums work?

You have some errors, so consider reading the solidity docs. Also, remix is a convenient tool for coding and debugging and coding exercises. I modified your code, as follows: pragma solidity ^0.5.0; ...
BinGoBinBin's user avatar
  • 2,161
20 votes
Accepted

are there "public" ethereum nodes? or any recommendations on hosting solutions?

Infura is the most prominent public Ethereum nodes. They run mainnet and many of the testnets. They also run IPFS servers. http://infura.io.
Thomas Jay Rush's user avatar
18 votes
Accepted

How can you handle an expected throw in a contract test using truffle and ethereum-testRPC?

You can use OpenZeppelin's expectThrow helper - Source: https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/test/helpers/expectThrow.js export default async promise => { try { ...
Sanchit's user avatar
  • 3,492
18 votes

Truffle's Ganache VS Testrpc

Ganache is TestRPC, it is like a rebranding. The github repo for ethereumjs-testrpc now redirects to ganache-cli. As of today 2017-12-20 if you install through npm, both npm install ethereumjs-...
Ismael's user avatar
  • 30.6k
17 votes

truffle has not been deployed to detected network

Sometimes I've run into a similar issue where truffle doesn't detect changes in my contracts and either it doesn't compile it or, when it does, it doesn't migrate it (saying network is up to date). ...
pabloruiz55's user avatar
  • 7,696
16 votes
Accepted

Truffle Smart Contract Testing does not reset state

To reset the state, you have to tell the test suite to deploy a new instance of the contract before it starts. You can tell it to deploy a new contract before each "it" with beforeEach(). Every test ...
Rob Hitchens's user avatar
  • 55.2k
16 votes
Accepted

truffle + testrpc time manipulation

You can use evm_increaseTime from truffle console to adjust timestamp of the next block. Here is an example (from this answer): > web3.eth.getBlock(web3.eth.blockNumber).timestamp 1500300000 > ...
max taldykin's user avatar
  • 2,966
15 votes
Accepted

Why use filters - eth_getLogs vs eth_newFilter

eth_getLogs returns an array of filter logs. You pass in the parameters - e.g. fromBlock, toBlock, etc. - you want to discriminate against. These are the same parameter used by eth_newFilter. ...
Richard Horrocks's user avatar
15 votes

What is the difference between testRPC and geth?

Test RPC is a client for testing: testrpc is a Node.js based Ethereum client for testing and development. It uses ethereumjs to simulate full client behavior and make developing Ethereum ...
KanekiDev's user avatar
  • 671
15 votes

How can I take a snapshot of Ganache or Truffle Develop state and reload later?

This can be done with the ganache-cli db command. For example, to run a setup similar to the GUI client, I do ganache-cli --db="./data/save/" -i="5777" -d --mnemonic="...
nickjm's user avatar
  • 865
14 votes

Setting the initial balance of an account in ganache-cli

OK, found it in the Ganache Command Line guide: -e or --defaultBalanceEther: Amount of ether to assign each test account. Default is 100. Apparently, ganache-cli --help doesn't quite tell you ...
goodvibration's user avatar
13 votes

Truffle invalid address

Thank's to Truffle Gitter channel I figured out. I have to call defaults function on my truffle-contract's abstraction. MyContract.defaults({from: …}) https://github.com/trufflesuite/truffle/tree/...
underdog's user avatar
  • 1,190
12 votes

How can you handle an expected throw in a contract test using truffle and ethereum-testRPC?

In my opinion the cleanest possible way is the following: it("should reject", async function () { try { await deployedInstance.myOperation1(); assert.fail("The transaction should ...
brickpop's user avatar
  • 221
12 votes
Accepted

Simulating the passage of time with testrpc

By default, every transaction called in testrpc is immediately mined and the block height will increase. The time it takes to mine each block can be set as a command line option when starting testrpc ...
arseniy's user avatar
  • 376
11 votes
Accepted

Call an arbitrary JSON-RPC method with web3

In addition to sendAsync, you can extend web3 like so: web3._extend({ property: 'evm', methods: [new web3._extend.Method({ name: 'snapshot', call: '...
Tjaden Hess's user avatar
  • 37.1k
11 votes

Problem with Truffle Console: Cannot read property 'call' of undefined

you could also use : HelloWorld.deployed().then(helloworld=> console.log(helloworld.balance.call())) or HelloWorld.deployed().then(function(instance){helloworld=instance}) then helloworld....
Badr Bellaj's user avatar
  • 18.8k
11 votes

How to use the testrpc `evm_increaseTime` parameter from truffle console?

You need to send JSON-RPC request to testrpc. Here is a helper function to call it from console: truffle(development)> const increaseTime = addSeconds => { web3.currentProvider.send({ ...
max taldykin's user avatar
  • 2,966
11 votes
Accepted

testrpc - how to write commands in console?

What you are typing into is just an informational screen, you can't execute commands from it. What you need is a JS console with web3 connected to testrpc via JSON RPC. A simple way that you can get ...
Tjaden Hess's user avatar
  • 37.1k
11 votes
Accepted

Truffle: Deploying contract with ether

I think possibly some misunderstanding. A handful of clarifications might help. Contracts cannot (yet) pay the gas for anything. Gas is always paid by a sender who sends a transaction to a contract ...
Rob Hitchens's user avatar
  • 55.2k
11 votes
Accepted

You must deploy and link the following libraries before you can deploy a new version of Contract

You should use the recommended fix in issue #501, the problem that it causes is that the truffle's artifacts are not updated in the right order. async function doDeploy(deployer, network) { ...
Ismael's user avatar
  • 30.6k
10 votes

How can you handle an expected throw in a contract test using truffle and ethereum-testRPC?

The other answers in this thread appear to be valid, however I believe this code is more succinct and readable. This works with solidity 0.4.12-develop it("should throw if the car is not blue", ...
paulhauner's user avatar
  • 1,248
10 votes
Accepted

invalid JUMP after upgrading truffle & testrpc

You need to put the payable modifier in your function. In the latest version of solidity, if a function does not have that modifier, it will throw (i.e. perform an invalid jump) if it receives ether.
Matthew Schmidt's user avatar
10 votes

'Error: base fee exceeds gas limit' When creating new contract instance (Using Truffle, Web3Js and testrpc)

Since your example code uses truffle-contract you can specify the default values for your transactions and contract deployments like this (Conferrence is the name of your contract. I used the truffle ...
hurb's user avatar
  • 391
10 votes
Accepted

MetaMask not showing the testrpc accounts

Got it working! had to run testrpc with testrpc -m <12 word metamask password that gives when downloading metamask>
Adam's user avatar
  • 271
10 votes
Accepted

Web3: How do I get just the first account on testrpc using web3.eth.getAccounts()?

Since web3.eth.getAccounts() returns a list of addresses you can access the first accounts's address easily just by e[0] in your example. So just try this: web3.eth.getAccounts().then(e => let ...
István András Seres's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible