Truffle deployment error: Returned error: gas required exceeds allowance or always failing transaction.
Dear Mr. Andrew, I have a piece of similar code, and I also ran the code in this repo, every time I execute truffle migrate --reset I got an error of exceeding allowance, could you give me some suggestions? Thank you in advance.
My environment:
- Private chain using Geth, gas limit in genesis.json is
0xffffffff - Nodejs 10.16.0
- Truffle 5.0.24
I am using the command truffle migrate --reset so I modified the development section directly, moreover, I deleted the singleton registry in the migration file
const Simple777Token = artifacts.require('Simple777Token');
const Simple777Recipient = artifacts.require('Simple777Recipient');
module.exports = async function (deployer, network, accounts) {
await deployer.deploy(Simple777Token);
const token = await Simple777Token.deployed();
await deployer.deploy(Simple777Recipient, token.address);
};
truffle-config.js:
development: {
host: '127.0.0.1', // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: '*', // eslint-disable-line camelcase
gas: 8000000,
confirmations: 2, // # of confs to wait between deployments. (default: 0)
timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
skipDryRun: true, // Skip dry run before migrations? (default: false for public nets )
},
Detailed error of my code:
2_deploy_sec_token.js
=====================
Deploying 'SECToken'
--------------------
> transaction hash: 0x9ef7bb1bbc985e0598e69a5b0f2b36fa99e89fa3023a892c997e17107edf4627
Error: Error: Error: *** Deployment Failed ***
"SECToken" received a generic error from Geth that
can be caused by hitting revert in a contract constructor or running out of gas.
* Returned error: gas required exceeds allowance (8000000) or always failing transaction.
* Try: + using the '--dry-run' option to reproduce this failure with clearer errors.
+ verifying that your gas is adequate for this deployment.
at Object.run (/usr/local/share/.config/yarn/global/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.24 (core: 5.0.24)
Node v10.16.0
Error message of your code:
2_deploy.js
===========
Deploying 'Simple777Token'
--------------------------
> transaction hash: 0x29998b492871f92839d46fcb5f51eff1ae6e0ce50b1756d5df39a76b482b737f
Error: Error: Error: *** Deployment Failed ***
"Simple777Token" received a generic error from Geth that
can be caused by hitting revert in a contract constructor or running out of gas.
* Returned error: gas required exceeds allowance (8000000) or always failing transaction.
* Try: + using the '--dry-run' option to reproduce this failure with clearer errors.
+ verifying that your gas is adequate for this deployment.
at Object.run (/usr/local/share/.config/yarn/global/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.24 (core: 5.0.24)
Node v10.16.0
Then I tried to use ropsten first, firstly I created a file named .env, the content looks like this:
DEV_MNEMONIC=xxx
INFURA_PROJECT_ID=xxx
Before execution, I have re-cloned this repo and there is no modification, then truffle migrate --network ropsten
The error message is:
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Error: Error: Expected parameter 'from' not passed to function.
at Object.run (/usr/local/share/.config/yarn/global/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
at runMigrations (/usr/local/share/.config/yarn/global/node_modules/truffle/build/webpack:/packages/truffle-core/lib/commands/migrate.js:241:1)
Truffle v5.0.24 (core: 5.0.24)
Node v10.16.0
I tried to comment out the deployment of Simple777Recipient, but it also did not work
Very appreciate for your insights, thank you!!
Hi @pupboss Apologies, I am so sorry. I only just saw this issue.
The best place to ask questions about this ERC777 example is in the OpenZeppelin community forum: https://forum.openzeppelin.com/t/simple-erc777-token-example/746
On your first question: A key point to note is that in a testing environment an ERC777 token requires deploying an ERC1820 registry using openzeppelin-test-helpers. The same applies to a private network.
On your second question:
I just cloned this repository, added a .env file and set my Infura Project ID and a 12 word seed phrase with testnet Ether.
.env
INFURA_PROJECT_ID="ADD INFURA PROJECT ID"
DEV_MNEMONIC="ADD 12 WORD SEED PHRASE"
I then deployed to Ropsten using:
npx truffle migrate --network ropsten
The deployed contract is at: https://ropsten.etherscan.io/token/0xC00ef2F9cc7a12001Af4D2c3689eAFe230757706
Hi @abcoathup
Thank you for your detailed reply, today I tested the latest code, the good new is that I successfully deployed it on both Ropsten network and Truffle test network, here is the address: https://ropsten.etherscan.io/token/0x8D8Ddc7D53e8ee162084bDF47A1db59EC9775509
However when I tried to deploy it on my private chain (via Geth), I am still facing the same issue. Anyway, thanks for your help.
Yeah one more thing, I already have a 1820 registry on my private chain and the address is exactly the same with example ERC777 code. Still have no idea how to solve the gas limit issue...I think it may not be a gas issue, truffle is misleading users...
2_deploy.js
===========
Deploying 'Simple777Token'
--------------------------
> transaction hash: 0x8847c45130e0c0e91412ac3c50c5302f77628338e6e4392551b79b102a4111b3
Error: Error: Error: *** Deployment Failed ***
"Simple777Token" received a generic error from Geth that
can be caused by hitting revert in a contract constructor or running out of gas.
* Returned error: gas required exceeds allowance (6721975) or always failing transaction.
* Try: + using the '--dry-run' option to reproduce this failure with clearer errors.
+ verifying that your gas is adequate for this deployment.
at Object.run (/Users/jetl/Desktop/fogchain-smart-contract/references/Simple777Token/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.31 (core: 5.0.31)
Node v10.16.3
Hi @pupboss,
On Ropsten, the gas used by the transaction to deploy the contract was 3,344,178 so I assume it is not running out of gas on your private network.
The next assumption is that the contract is reverting in the constructor, potentially when registering the interfaces with the already deployed ERC1820 contract?