mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 03:28:07 +00:00
contract deploy returns now new instance
This commit is contained in:
parent
c800df8d6d
commit
fd2d0269fc
@ -248,7 +248,7 @@ deploy
|
||||
myContract.deploy(options)
|
||||
|
||||
Call this function to deploy the contract to the blockchain.
|
||||
After successfull deployment the ``myContract.options.address`` will be set automatically to the newly deployed contract.
|
||||
After successfull deployment the promise will resolve with a new contract instance.
|
||||
|
||||
----------
|
||||
Parameters
|
||||
@ -266,7 +266,7 @@ Returns
|
||||
``Object``: The transaction object:
|
||||
|
||||
- ``Array`` - arguments: The arguments passed to the method before. They can be changed.
|
||||
- ``Function`` - :ref:`send <contract-send>`: Will deploy the contract.
|
||||
- ``Function`` - :ref:`send <contract-send>`: Will deploy the contract. The promise will resolve with the new contract instance, instead of the receipt!
|
||||
- ``Function`` - :ref:`estimateGas <contract-estimateGas>`: Will estimate the gas used for deploying.
|
||||
- ``Function`` - :ref:`encodeABI <contract-encodeABI>`: Encodes the ABI of the deployment, which is contract data + constructor parameters
|
||||
|
||||
@ -290,11 +290,11 @@ Example
|
||||
.on('error', function(error){ ... })
|
||||
.on('transactionHash', function(transactionHash){ ... })
|
||||
.on('receipt', function(receipt){
|
||||
// same as when the promise gets resolved, see below
|
||||
console.log(receipt.contractAddress) // contains the new contract address
|
||||
})
|
||||
.on('confirmation', function(confirmationNumber, receipt){ ... })
|
||||
.then(function(receipt){
|
||||
console.log(myContract.options.address) // gives the new contract address
|
||||
.then(function(newContractInstance){
|
||||
console.log(newContractInstance.options.address) // instance with the new contract address
|
||||
});
|
||||
|
||||
|
||||
@ -309,8 +309,8 @@ Example
|
||||
gas: 1500000,
|
||||
gasPrice: '30000000000000'
|
||||
})
|
||||
.then(function(receipt){
|
||||
console.log(myContract.options.address) // gives the new contract address
|
||||
.then(function(newContractInstance){
|
||||
console.log(newContractInstance.options.address) // instance with the new contract address
|
||||
});
|
||||
|
||||
|
||||
@ -484,7 +484,7 @@ Returns
|
||||
|
||||
The **callback** will return the 32 bytes transaction hash.
|
||||
|
||||
``PromiEvent``: A :ref:`promise combined event emitter <promiEvent>`. Will be resolved when the transaction *receipt* is available. Additionally the following events are available:
|
||||
``PromiEvent``: A :ref:`promise combined event emitter <promiEvent>`. Will be resolved when the transaction *receipt* is available. If this ``send()`` is is called from a ``someContract.deploy()`` then the promise will resolve with the *new contract instance*. Additionally the following events are available:
|
||||
|
||||
- ``"transactionHash"`` returns ``String``: is fired right after the transaction is send and a transaction hash is available.
|
||||
- ``"receipt"`` returns ``Object``: is fired when the transaction receipt is available.
|
||||
|
@ -231,7 +231,14 @@ Method.prototype._confirmTransaction = function (defer, result, payload, extraFo
|
||||
|
||||
if (code.length > 2) {
|
||||
defer.eventEmitter.emit('receipt', receipt);
|
||||
|
||||
// if contract, return instance instead of receipt
|
||||
if (extraFormatters && extraFormatters.contractDeployFormatter) {
|
||||
defer.resolve(extraFormatters.contractDeployFormatter(receipt));
|
||||
} else {
|
||||
defer.resolve(receipt);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
utils._fireError(new Error('The contract code couldn\'t be stored, please check your gas limit.'), defer.eventEmitter, defer.reject);
|
||||
|
@ -777,16 +777,33 @@ Contract.prototype._executeMethod = function _executeMethod(){
|
||||
if (_.isArray(receipt.logs)) {
|
||||
|
||||
// decode logs
|
||||
receipt.events = _.map(receipt.logs, function(log) {
|
||||
var events = _.map(receipt.logs, function(log) {
|
||||
return _this._parent._decodeEventABI.call({
|
||||
name: 'ALLEVENTS',
|
||||
jsonInterface: _this._parent.options.jsonInterface
|
||||
}, log);
|
||||
});
|
||||
|
||||
// make log names keys
|
||||
receipt.events = {};
|
||||
var count = 0;
|
||||
events.forEach(function (ev) {
|
||||
if (ev.event) {
|
||||
receipt.events[ev.event] = ev;
|
||||
} else {
|
||||
receipt.events[count] = ev;
|
||||
count++;
|
||||
}
|
||||
});
|
||||
|
||||
delete receipt.logs;
|
||||
}
|
||||
return receipt;
|
||||
},
|
||||
contractDeployFormatter: function (receipt) {
|
||||
var newContract = _this._parent.clone();
|
||||
newContract.options.address = receipt.contractAddress;
|
||||
return newContract;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1388,8 +1388,9 @@ describe('contract', function () {
|
||||
transactionHash: '0x1234',
|
||||
blockNumber: 10,
|
||||
gasUsed: 0,
|
||||
events:
|
||||
[ { address: address,
|
||||
events: {
|
||||
Unchanged: {
|
||||
address: address,
|
||||
blockNumber: 10,
|
||||
transactionHash: '0x1234',
|
||||
blockHash: '0x1345',
|
||||
@ -1408,7 +1409,8 @@ describe('contract', function () {
|
||||
'0x000000000000000000000000' + addressLowercase.replace('0x', '')],
|
||||
data: '0x0000000000000000000000000000000000000000000000000000000000000005',
|
||||
}
|
||||
}, {
|
||||
},
|
||||
Changed: {
|
||||
address: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
|
||||
blockNumber: 10,
|
||||
transactionHash: '0x1234',
|
||||
@ -1429,7 +1431,8 @@ describe('contract', function () {
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000001'],
|
||||
data: '0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000008',
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
done();
|
||||
@ -1993,10 +1996,15 @@ describe('contract', function () {
|
||||
})
|
||||
.on('receipt', function (receipt) {
|
||||
assert.equal(address, receipt.contractAddress);
|
||||
assert.isNull(contract.options.address);
|
||||
})
|
||||
.then(function(receipt) {
|
||||
assert.equal(address, receipt.contractAddress);
|
||||
.then(function(newContract) {
|
||||
assert.equal(newContract.options.address, address);
|
||||
assert.isTrue(newContract !== contract, 'contract objects shouldn\'t the same');
|
||||
|
||||
setTimeout(function () {
|
||||
done();
|
||||
}, 1);
|
||||
});
|
||||
// .on('error', function (value) {
|
||||
// console.log('error', value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user