3

I am trying to deploy a smart contract on a private blockchain using Geth. I followed many "tutorials" (not sure I can call it like this considering how poor they are). Never worked.

I tried the folowing:

Using the second one, I have a problem, my contract instance deos not have any address, it's a bit annoying if I want to use it!

Indeed, I deploy the contract using the folowing:

> myContractInstance = myContract.new(txDeploy)
INFO [10-24|05:45:24] Submitted contract creation              fullhash=0x3548898e19f7e568e
bf9ab117abbfb9bcc8833c72c027dca6ce2af980ebde7be contract=0x615ca1B75D11ffb88C8cFC866e7e9114
B9ec8112

I then mine a few blocks to confirm transaction.

When I try to get the contract address, the address is undefined:

    myContractInstanceEnd = myContract.at(myContractInstance.address)
    {
      abi: [{

//All the stuff

}],
  address: undefined,
  transactionHash: null,

If I just want to get the address:

myContractInstanceEnd.address undefined

Does someone know why and also, do you know an UP TO DATE source that tells how to do this?

2
  • Post your code for txDeploy
    – jojeyh
    Oct 24, 2017 at 15:26
  • Truffle make things a lot easier for both beginners and advanced, check youtube tutorials.
    – Ozgur
    Oct 25, 2017 at 13:49

2 Answers 2

3

If you are working on private network during test and development phase use truffle its best, if working on testRPC or Geth. Just follow the follwing steps

  1. open Console window and run this command npm install -g truffle
  2. create a project directory and run this command inside it truffle init
  3. it will create the follwing folder structure enter image description here

  4. in truffle.js define your network configruation like this

  module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8045, // your can use your port number
      network_id: '*' // Match any network id
    }
  }
}
  1. then in migration folder delete other files except 1_initial_migration and create another js file with the name 2_deploy_contract.js with the follwing contents
var MyContract = artifacts.require("MyContract");

module.exports = function(deployer) {   // deployment steps   deployer.deploy(MyContract); };
  1. open a console in the project directory and run the command truffle compile
  2. the run this command truffle migrate --reset, during this operation keep your miner in running condition. At the completion it will give a message contract successfully depolyed. And in the build folder you can check yourcontract.json file is created. So in future just reference it.
  3. now open console and run this command truffle console

  4. then run this command yourContractName.address, it will give your contract address.

2

Here is a good intro example tutorial for starting a private network and deploying a contract.

https://alanbuxton.wordpress.com/2017/07/19/first-steps-with-ethereum-private-networks-and-smart-contracts-on-ubuntu-16-04/

Good luck!

Your Answer

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

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