The Stack Overflow podcast is back! Listen to an interview with our new CEO.
39

You can force truffle to use a specific solc version by installing that version directly in the truffle directory. For example on Ubuntu the following with force truffle to use 0.4.15 $ cd /usr/local/lib/node_modules/truffle $ npm install solc@0.4.15 truffle version will still show the default version but it will in fact utilize the updated version. You ...


23

On windows systems having truffle.js in your main folder may create a conflict when you try to execute truffle. Windows first try for executables in your current directory, and .js files are considered executables, then when it tries to execute your configuration file it will fail. To be compatible with windows you can either rename your configuration file ...


13

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/develop/packages/truffle-contract buildContracts() { let contracts = {}; let meta; this.props.contracts.forEach( _contract => { let {...


12

If you're using ^v5.0.0 (including beta releases), you can bring your own compiler by adding this in your truffle config file (in this example it's set to 0.4.25): module.exports = { ... compilers: { solc: { version: "0.4.25", }, }, ... }; You can query the list of available compiler versions by running this: truffle compile --list


11

I figured it out. in truffle.js you can specify from: field like this: // Allows us to use ES6 in our migrations and tests. require('babel-register') module.exports = { networks: { development: { host: 'localhost', port: 8545, network_id: '*', // Match any network id from: '0xA21983B35C767CF8609D95F4886C9A18A194D8AA' } } ...


9

After a couple of attempts, I've made it by uninstalling and installing truffle, exactly as described in here: npm uninstall -g truffle npm install -g truffle That updated Truffle itself though, along with the compiler.


6

Ok, finally I added some code to unlock account on the fly. I do not want to store password in truffle.js (but it is possible), so doing next things: Changed 1_initial_migration.js this way: const Web3 = require('web3'); const TruffleConfig = require('../truffle'); var Migrations = artifacts.require("./Migrations.sol"); module.exports = function(...


6

Add this in your Truffle configuration file (truffle.js or truffle-config.js): mocha: { enableTimeouts: false, before_timeout: 120000 // Here is 2min but can be whatever timeout is suitable for you. } If you want to preserve timeouts (and even configure different timeouts for different tests), then simply follow the instructions here.


6

You need to upgrade your truffle to do that. npm install -g truffle@X For example, to get solc 0.4.11 support, install truffle 3.2.2 or above. npm install -g truffle@3.2.2 or npm update -g truffle@3.2.2


6

According to the truffle documentation, the two arguments gas and gasPrice stand for: gas: Gas limit used for deploys. Default is 4712388. gasPrice: Gas price used for deploys. Default is 100000000000 (100 Shannon). For the gasPrice: it's easy, higher is the price, faster your transaction will be mined. On the testnet (Ropsten), as the ether doesn't worth ...


4

You should use truffle.js And from this page of Truffle docs my understanding is that: Both files are created on initiation because default configuration file name can cause a conflict with the truffle executable, and so you may not be able to run Truffle commands properly on existing projects.


4

truffle.js and do add the following to it module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*" // Match any network id } } };


4

inside module.exports, add Gas and gasPrice. network_id: "*", // Match any network id gasPrice: 0, gas: 4500000


3

Just for reference, as of Truffle v5, truffle-config.js is now the default (and only file that is created) when initializing a new project.


3

One thing that can cause this behaviour with Parity (not sure if that's what the Azure service is running or not) is that if the account it wants to deploy with is locked, as it is by default, it expects you to take some other step to approve the transaction. Parity tries to do this by running a web UI on some other port, showing each transaction request on ...


3

This worked for me. Hope my answer helps future readers. You have to the set the defaultAccount to be used: web3.eth.defaultAccount = web3.eth.accounts[0]; before using web3 instance. Also, In my case where I'm using react-truffle box, the invalid address can be solved by adding. this.state.web3.eth.defaultAccount = this.state.web3.eth.accounts[0]; ...


3

There is an issue in a way you use HDWalletProvider when configuring development network in truffle-config.js. You should add it like: provider: () => new HDWalletProvider('your mnemonic', 'http://127.0.0.1:7545') For me, it helped. Additional info can be found here.


2

There might be a newer, better way, but this has always worked for me. Go to geth, and web3.personal.unlockAccount(web3.personal.listAccounts[0], "<password>", 15000); 15000 (seconds) just tells it to keep the first account unlocked for a long time so you can work in peace. Hope it helps.


2

I had an owner withdrawal function in my smart contract that would throw the following error: Uncaught (in promise) Error: invalid address I eventually realized that either Truffle or MetaMask expects an explicit from address. This was my original function definition: ownerWithdrawal() { return this.contractInstance.ownerWithdrawal(); // calls ...


2

Check your solc compiler version using the following command - solc --version Then you can use following commands to uninstall solc(solidity) compiler and install it again. It shall give you latest version(0.4.11) - npm uninstall solc -g npm install solc@0.4.11 Check the solc version after installing it again. In order to see the information of ...


2

You can change the gas provided in truffle.js. Also, have in mind that truffle 4 has the optimizer turned off by default, so you'll probably want to turn it on if the contract still doesn't get deployed. module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*", // Match any network id gas: ...


2

Ganache is a development chain which is not able to use a different consensus mechanism. Ganache accepts all incoming transactions immediately and creates one block for each by default. You could describe it as proof-of-authority chain with just one node. Ganache does not use a genesis.json file. The chain is defined by the options you pass to Ganache. The ...


2

Truffle does not distinguish between truffle.js and truffle-config.js. So, an easy way to deal with this, as referenced in Mastering Ethereum, is to simply delete this and use truffle-config.js instead.


2

This is tracked by Truffle issue #1879. (Not entirely sure what the code flow would be after its implementation, but getTruffleConfig.js might be a good place to start having a poke around if you're feeling brave.)


1

If your on Linux, type which truffle I get this /home/dave/.nvm/versions/node/v8.11.1/bin/truffle then open that file in a text editor, and find the variable called defaultEtherBalance, I found it on line 581569. Save and restart truffle develop!


1

The command truffle develop launches an instance of ganache-cli (previously testrpc). If you only want to interact with an ethereum client for testing purposes you can launch it directly. To install (only do this once): $ npm install -g ganache-cli To execute: $ ganache-cli


1

When running truffle test it will use testrpc as default network. So, in order to configure account balances you would do it as you are doing now. Truffle test will connect to testrpc and use the accounts in there.


1

in the configuration file of truffle (truffle.js), in the networks group, you can specify a from field with an address, which is going to be used by default when sending transactions on that network. For example I have this entry for Rinkeby: rinkeby: { host: "localhost", port: 8545, network_id: 4, from: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", //...


1

I found workaround for this case, just add provider field to truffle.js: const Web3 = require('web3'); module.exports = { networks: { ropsten: { ................. provider: new Web3.providers.HttpProvider('https://host.name:8545') }, rinkeby: { ...... provider: new Web3.providers.HttpProvider('https://host.name:8546') ...


1

In the latest truffle after 5.x.x, it is possible to specify compiler version in truffle-config.js: module.exports = { networks: { ... etc ... }, compilers: { solc: { version: <string> // ex: "0.4.20". (Default: Truffle's installed solc) } } }; Reference: https://github.com/trufflesuite/truffle/releases/tag/v5.0.0-beta....


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