Private Blockchain – How to Deploy Smart Contract to a Predefined Address

contract-deploymentprivate-blockchain

Is there any method to deploy our smart contract in a particular address (ie. predefined contract address) in private ethereum network?

Yes, I have built my own private blockchain based on Ethereum code. I need to deploy contract on some blocks and I have to send that address to my client ( users). In this scenario, I don't want to send a different address to the client while I am deploying a contract. If it was a static address it will be easy for me. I will just inform them I have deployed a new contract so that they can use the static address to get input for their code.

Best Answer

It is not possible to deploy a contract to an address of your choice

The address a contract is deployed to is generated deterministically using the address of the deployer and the deployer's total number of transactions (the nonce): How is the address of an Ethereum contract computed?

This means you can work out the address of the contract before it is deployed:

var ethJsUtil = require('ethereumjs-util');
var futureAddress = ethJsUtil.bufferToHex(ethJsUtil.generateAddress(
  yourAddress,
  web3.eth.getTransactionCount(yourAddress)));

(from https://stackoverflow.com/a/42416934)

Related Topic