I am trying to deploy a contract in Ethereum testnet, with the web3 API via my geth node. The contract is deployed correctly and I can see the address in geth and verify it exists on etherscan. However I can't get the contract address working in my javascript. My code is:
var myContractReturned = web3.eth.contract(abi).new({data: code,gas:500000}, function (err, contract) {
if(err) {
console.error(err);
return;
} else if(contract.address){
console.log('ContractAddress: ' + contract.address);
document.getElementById('status').innerText = 'Mined!';
}else{
console.log('ContractAddress: ' + contract.address);
}
});
In the If statement the only part that is executed is the "else" and contract.address returns undefined.