0
votes

I have a smart contract which I am deploying using the Web3.js package. I have a function called deploySmartContract() which does so, and I am expecting this method to return contract address to the calling function. Below is the snippet for deploySmartContract() -

function deploySmartContract(shareName, symbol, maxSupply) {
    var _shareName = shareName;
    var _symbol = symbol;
    var _maxSupply = maxSupply;
    var contractAddr = '';

    var sharesregistry = contractObj.new(
        _shareName,
        _symbol,
        _maxSupply,
        {
            from: primaryAccount, 
            data: byteCode, 
            gas: '5000000'
        }, function (e, contract){
            console.log(e, contract);
            if (typeof contract.address !== 'undefined') {
                console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
            }
        }
    );
    console.log(sharesregistry.address);

    return sharesregistry;
}

How can I keep my return statement waiting unless the whole transaction is completed and execute return when contract is mined? Else I am getting just an skeleton of shareregistry object at the calling function.

Here, I confirm that this code deploys the smart contract perfectly.

1

1 Answers

0
votes

Checkout API new method and how to call it synchronously and asynchronously. You have provided callback functions which means you run it asynchronously. By removing it, you force it to wait for a result.