I developed my smart contract using tesrpc. Now I want to deploy them on the testnet. But I am not able to deploy them either with EtherWallet (I have the error "No data is deployed in the contract address", even if I maxed the fees) or with a JS script using the web3 api where i set Gas to 4700000. But i have no smart contract address back.
My smart contract code is:
pragma solidity ^ 0.4.2;
contract Color {
address public contracts;
string public color;
function Color(address _c, string _color) {
contracts = _c;
color = _color;
}
function getContracts() constant returns(address contractAddress) {
return contracts;
}
function getColor() constant returns(string color) {
return color;
}
function setlastDirAddress(address c) {
contracts = c;
}
function setColor(string clr) {
color= clr;
}
}
EDIT: Here is my JS script:
var Web3 = require('web3');
var solc = require('solc');
const fs = require('fs');
//Globals
var colorContract = {
abi: null,
address: null
};
//connect to testRPC / Geth locally
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
// Checking Ethereum connection status
if (!web3.isConnected()) {
console.error("Ethereum - no conection to RPC server");
} else {
console.log("Ethereum - connected to RPC server");
}
//Setting up the account
web3.eth.defaultAccount = web3.eth.accounts[0];
var account = web3.eth.accounts[0];
function compileAndDeployColorContract() {
var contractAddress = process.argv[2];
var color = process.argv[3];
let source = fs.readFileSync('./color.sol', 'utf8');
let compiledContract = solc.compile(source, 1);
let abi = compiledContract.contracts['Color'].interface;
fs.writeFile('./colorABI.js', abi, (err) => {
if (err) throw err;
console.log('colorABI.js saved!');
});
let bytecode = compiledContract.contracts['Color'].bytecode;
let gasEstimate = web3.eth.estimateGas({
data: bytecode
});
//run out of gas when using this
let colorContract = web3.eth.contract(JSON.parse(abi));
//Contract Object parameters
var deployContractObject = {
from: account,
data: bytecode,
gas: '4700000'
};
var colorSC = colorContract.new(contractAddress, color, deployContractObject, function(err, colorSC) {
if (!err) {
// NOTE: The callback will fire twice!
// Once the contract has the transactionHash property set and once its deployed on an address.
// e.g. check tx hash on the first call (transaction send)
if (!colorSC.address) {
console.log('ColorTransaction Hash: ' + colorSC.transactionHash) // The hash of the transaction, which deploys the contract
// check address on the second call (contract deployed)
} else {
console.log('ColorContract Mined! address: ' + colorSC.address) // the contract address
}
// Note that the returned "myContractReturned" === "myContract",
// so the returned "myContractReturned" object will also get the address set.
}
else { console.log(err);}
});
}
compileAndDeployColorContract();
I already had a look here, here and here.
Thanks for your answers,
console.log("Ethereum - connected to RPC server");this line is being executed? – Aniket Apr 28 '17 at 10:31