Unable to deploy an Interface when it is in a separate .sol file
See original GitHub issue- I’ve asked for help in the Truffle Gitter before filing this issue.
Issue
In my repository https://github.com/ltfschoen/dao. I want move the Token
Interface out of the TokenInterface.sol file and into its own file called Token.sol with contents:
pragma solidity ^0.4.19;
interface Token {
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
}
And then import Token.sol into TokenInterface.sol with import "./Token.sol";
I then want to updated this file that deploys my contracts and links to libraries and interfaces to link the Token.sol interface to TokenRecipient prior to deploying TokenRecipient, by importing const Token = artifacts.require("./Token.sol");
, and then linking Token to TokenRecipient before deploying TokenRecipient and Congress by adding deployer.link(Token, TokenRecipient);
, so 2_deploy_contracts.js would become:
const Owned = artifacts.require("./Owned.sol");
const Token = artifacts.require("./Token.sol");
const TokenRecipient = artifacts.require("./TokenRecipient.sol");
const Congress = artifacts.require("./Congress.sol");
module.exports = (deployer) => {
// Deploy library Owned, Token, and TokenRecipient
deployer.deploy(Owned);
deployer.deploy(Token);
// Link Token to TokenRecipient before deploying Congress
deployer.link(Token, TokenRecipient);
deployer.deploy(TokenRecipient);
// Link Owned and TokenRecipient to contract Congress before deploying Congress
deployer.link(Owned, Congress);
deployer.link(TokenRecipient, Congress);
// Deploy contract Congress
deployer.deploy(Congress, 0, 0, 0);
};
However, after making these changes, I then start Ganache CLI as usual with:
ganache-cli \
--port="8500" \
--mnemonic "copy obey episode awake damp vacant protect hold wish primary travel shy" \
--verbose \
--networkId=3 \
--gasLimit=7984452 \
--gasPrice=2000000000;
But when I try to deploy the contracts by running truffle migrate --network development
, it gives me error:
$ truffle migrate --network development
Compiling ./contracts/Congress.sol...
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/Owned.sol...
Compiling ./contracts/Token.sol...
Compiling ./contracts/TokenRecipient.sol...
Writing artifacts to ./build/contracts
Using network 'development'.
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0x39217f6841bbdaef54fc759d3a6ff2b4e6455eaa02e417839c4d5826bb696129
Migrations: 0x5b80e4653adbc5e8e2387474d4de0eeed34779ea
Saving successful migration to network...
... 0x910366905fa49da62c436bbb01f32f676063ed63e4988fad270122c625dd3192
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying Owned...
... 0x9d76b243b694da1765146293224ce2d100935692e66428a54e868c52a875edaa
Owned: 0x4cdb6ac6c502d9dca1a0b70fdc1cd7e64f89e1bf
Deploying Token...
... 0xf4b996e65b518f8c87190bfb7d596629d6e8c3fe01a0fb1bd5607fa9d2af1737
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.
at Object.callback (/Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/contract.js:147:1)
at /Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/method.js:142:1
at /Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:89:1
at /Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/truffle-migrate/index.js:225:1
at /Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (/Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (/Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
at XMLHttpRequest._setReadyState (/Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (/Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
at IncomingMessage.<anonymous> (/Users/Ls/.nvm/versions/node/v8.7.0/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
Note: For information about Interface, see the docs here: http://solidity.readthedocs.io/en/develop/contracts.html?highlight=interface#interfaces
Steps to Reproduce
- Clone repository https://github.com/ltfschoen/dao
- Install dependencies:
npm install -g truffle ganache-cli
- Switch to branch refactor-token where I have made the changes that result in the error
- Run Ganache CLI in a separate Terminal window
ganache-cli \
--port="8500" \
--mnemonic "copy obey episode awake damp vacant protect hold wish primary travel shy" \
--verbose \
--networkId=3 \
--gasLimit=7984452 \
--gasPrice=2000000000;
- Remove /build directory
rm -rf build/
- Run the migrations to deploy the contracts to the Test network of Ganache CLI
truffle migrate --network development
- Observe the error that gets produced, as mentioned previously
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.
Expected Behavior
I expect to be able to move an Interface into a separate file and link it to other contracts that depend upon it
Actual Results
See section “Steps to Reproduce”
Environment
- Operating System: macOS 10.12.6
- Truffle version: Truffle v4.0.4 (core: 4.0.4) Solidity v0.4.18 (solc-js)
- Ethereum client: Parity v1.8.9-stable
- node version: v8.7.0
- npm version: 5.5.1
- Ganache CLI v6.0.3 (ganache-core: 2.0.2)
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (7 by maintainers)
@ltfschoen It looks like the issue here might be that
interface
is an abstract contract which is meant to be used with the inheritance pattern. Could you see if removing the interface deployments / linkages from the migrations and substituting them with something like the following in your Solidity contract definitions achieves what you’re aiming for?Ahhh! That makes sense. Thanks for showing your solution too - I searched a little yesterday and couldn’t find any other examples of someone doing what you’re trying to do so this very useful. Much appreciated.