I'm currently using web3 0.20.6 and I'm planning to stay in [email protected] because there are issues with HTTP in the beta versions of [email protected].* like
The current provider doesn't support subscriptions: HttpProvider
Now I'm trying to figure out how to get the contract address after being deployed. Because in [email protected].*, we can use like the example below to get the contract address.
contract.deploy({
data: '0x'+bin,
arguments: [request.body.vin, cost, request.body.buyer]
})
.send({
from: request.body.dealer,
gas: gas
})
.on('receipt', receipt => {
util.log(`>>>>> contractApi - Contract sucessfully deployed @ address: ${receipt.contractAddress}`);
data.contract_address = receipt.contractAddress;
response.json(data);
});
But how do you do it in [email protected] ? I couldn't find the solutions online without using truffle. I'm not planning to use truffle as well.
What I did try was,
const deployedContract = LoginContract.new ({
data: '0x'+binLogin,
from: '6ded1c5b448819a6cde4293e33fbe54583ef5c52',
gas: 4700000
});
contractData = deployedContract.address;
util.log(`>>>>> setup - Login Contract sucessfully deployed @ address: ${contractData}`)
But the result in console is undefined address
22 Mar 14:04:15 - >>>>> setup - Login Contract sucessfully deployed @ address: undefined
Then after about 5-10 seconds, this popped up in the console
Error: The contract code couldn't be stored, please check your gas amount.
I'm like super confused right now because the gas amount should be sufficient.
EDIT 1 Thanks to @mirg's answer, the deployment is successful. However, I noticed that the instructions below the contract deployment:
contractData = deployedContract.address;
util.log(`>>>>> setup - Login Contract sucessfully deployed @ address: ${contractData}`)
continue to run and does not wait for the contract deployment to complete/finish.
How do you make further instructions to wait and process the result of that contract deployment? In [email protected].* it is achievable by using
.on('receipt', receipt => {}
But I have no idea how it is achieved using [email protected].