How exactly are the contract addresses created that are returned by the DeployNewXYZ() method a bound contracts? Is it possible that, if the method is called rapidly consecutively, the same address is returned twice?
I am using this method of a bound contract to deploy a new one:
// DeployTemperatureMeasurementA deploys a new Ethereum contract, binding an instance of TemperatureMeasurementA to it.
func DeployTemperatureMeasurementA(auth *bind.TransactOpts, backend bind.ContractBackend, _temperatureWriter common.Address, _minTemperature int8, _maxTemperature int8, _maxFailureReports uint16, _storageLocation string) (common.Address, *types.Transaction, *TemperatureMeasurementA, error) {
parsed, err := abi.JSON(strings.NewReader(TemperatureMeasurementAABI))
if err != nil {
return common.Address{}, nil, nil, err
}
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TemperatureMeasurementABin), backend, _temperatureWriter, _minTemperature, _maxTemperature, _maxFailureReports, _storageLocation)
if err != nil {
return common.Address{}, nil, nil, err
}
return address, tx, &TemperatureMeasurementA{TemperatureMeasurementACaller: TemperatureMeasurementACaller{contract: contract}, TemperatureMeasurementATransactor: TemperatureMeasurementATransactor{contract: contract}}, nil
}
This method is called like this:
address, _, _, err := contracts.DeployTemperatureMeasurementA(auth, backend, auth.From, minTemp, maxTemp, maxFailures, "")
I am only interested in storing the contract address. I am using this address to generate a binding to the contract at a later time.
Now, I call this method twice in a row in a for loop, I want to create two or more new instances of the bound contracts and store the addresses in a database.
When I do this, the Geth client produces two transactions but the contract address that results is the same (this is from the log of the geth client):
I0727 12:47:13.547767 eth/api.go:1203] Tx(b296bc8d329b2bb1002537040e997fd52a74fb6f0e4a749f685b3cfa968d42e0) created: cb744eb36354ada463dbe40fbf969c2d17f48e33
I0727 12:47:13.549639 eth/api.go:1203] Tx(ab1edcd1f39d64807921e92dea1680bc8224422738a5c45a0089aaac55a3594a) created: cb744eb36354ada463dbe40fbf969c2d17f48e33
I use a custom block chain to develop, the genesis file of my blockchain is this:
{
"nonce": "0xdeadbeefdeadbeef",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0",
"gasLimit": "0x8000000",
"difficulty": "0x20000",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0133ee9831e6eee82731578e25ba8361837fa5a5",
"alloc": {
"0x0133ee9831e6eee82731578e25ba8361837fa5a5": {
"balance": "1000"
}
}
}
I use geth Version: 1.5.0-unstable, installed with Homebrew on Mac OSX 10.11.6 (15G31)