1

I'm trying to deploy a contract by two different ways, I can't succeed in any.
First way:
1. geth console —rinkeby —rpc —rpcapi db,eth,net,web3,personal —unlock="0x..." 2>>geth.log
I have ether on my account, I enter my password correctly, I'm sure that account is on eth.accounts list
2. I compile my contract with solc, it gives me binary code and abi, which I put into variables bin and abi. I put 0x before binary code.
3. var contract = web3.eth.contract(abi)
4. var token = myContract.new( {from: eth.coinbase, data: bin, gas: 1000000}, function(e, myContract) { if (e) { console.log(e); } else { if (myContract.address) { console.log ("mined " +myCcontract.address); } } })

And it says that

Error: The contract code couldn't be stored, please check your gas amount.

Second way is by using Truffle. I've succeeded in deploying contract to rinkeby lots of times already, but now I'm stuck on this error.
1. I run geth and unlock account
2. There is my truffle.js :

module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*", gas: 900000 },
rinkeby: {
host: '127.0.0.1',
port: 8545,
network_id: 4,
gas: 4612388, // Gas limit used for deploys
from: "0xeb1eb48fc3c2756cde3dce8a53472e437062f976" } } };

3.truffle migrate --reset --network rinkeby
And it says

Error encountered, bailing. Network state unknown. Review successful transactions manually. TypeError: contract.detectNetwork is not a function at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:201861:21 at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:326484:15 at

My purpose was to learn how to interact with contract's functions by geth or truffle console. But smth went wrong. Please, help me fix it.
If you made it to the end of this question, thanks already

2 Answers 2

1

try first with testrpc - https://github.com/ethereumjs/testrpc.

And this error message "Error encountered, bailing. Network state unknown" means that geth is not working properly or is not using port 8545 or it is not working because of the ip 127.0.0.1.

Try with testrpc. You are going to have a great experience. It is faster to interact with contracts for testing purpose

2
  • I will try it now just to find out, will it deploy or not But I need to deploy to testnet, so my coleques could try to interact with it. Commented Nov 21, 2017 at 12:04
  • Another way to connect to a node without geth is using infura. Don´t forget to run "npm install truffle-hdwallet-provider" Here is the text to add inside truffle.js: var HDWalletProvider = require("truffle-hdwallet-provider"); var mnemonic = "your accounts words"; module.exports = { migrations_directory: "./migrations", networks: { rinkeby: { provider: new HDWalletProvider(mnemonic, "rinkeby.infura.io/"), gas: 4500000, network_id: 4 } } } Commented Nov 21, 2017 at 12:26
0

Alternativelly I've writen a small lib for deployment that may be of use to someone. It deploys using ethers.js (the stable cousin of web3.js) and it is verbose and shiny :)

const etherlime = require('etherlime');

const ICOTokenContract = require('./build/contracts/ICOToken.json');

const randomAddress = '0xda8a06f1c910cab18ad187be1faa2b8606c2ec86';

const defaultConfigs = {
    gasPrice: 20000000000,
    gasLimit: 4700000
}

const deployer = new etherlime.InfuraPrivateKeyDeployer('Your Privste KEY', 'ropsten', 'Your infura API key', defaultConfigs);

const runICODeployment = async () => {
    const contractWrapper = await deployer.deploy(ICOTokenContract);
    const transferTransaction = await contractWrapper.contract.transferOwnership(randomAddress);
    const result = await contractWrapper.verboseWaitForTransaction(transferTransaction.hash, 'Transfer Ownership');
}
runICODeployment()

Put this in a file and run it with node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.