I am new to promises. I am using Bluebird promises for running an async function in this fashion.
var contract_creation = function creation(contractName){
return new Promise(function (resolve,reject){
web3.eth.sendTransaction(
{
from: web3.eth.accounts[0],
data:contractsJSON[contractName].bytecode,
gas:gasprice
},
function(err, transactionHash){
if(err){
reject(err);
}else{
resolve(transactionHash);
}
}
);
});
}
var getCreatedContract = function getReceipt(name){
contract_creation(name)
.then(function(transactionHash){
return web3.eth.getTransactionReceipt(transactionHash);
});
}
getCreatedContract("Fund").then(function(receipt){
console.log(receipt);
});
sendTransaction is an async operation which takes time.
After running this I am getting this exception.
getCreatedContract("Fund").then(function(receipt){
^
TypeError: Cannot read property 'then' of undefined
Can't I return something from .then() and that would also be a promise. What is the correct way of returning values from promise functions ?
returnthe new promise from your actual function - Bergi