0

The code returns undefined. When I check the testrpc command response the transaction confirmation can be seen from the deploy code.

contract.deploy({
    data: crJSON.bytecode,
    arguments: ['lol']
})
.send({
    from: acc,
    gas: 1500000,
    gasPrice: '300000'
});

contract.methods.createPatient(12112333).send({from: acc},function(error, result){
    console.log(result)
 });

contract.methods.updatePatient(12112333,"aa",1,2,"abb").send({from: acc}, function(error, result){
   console.log(result)

});

contract.methods.getbirth(123112333).call({from: acc},function(error, result){
    console.log(toString(result))
});

The calls are not occuring one by one I think. Also how do I get the return value of getbirth function?

1

Web3js v1.0 only support asynchronous calls and transactions. As you say the transaction seems not to be executing in the expected order. For asynchronous function you have to force them to execute in order using callbacks, promises or async/await.

Using promises it should look something like this:

var instance;
contract.deploy({
    data: crJSON.bytecode,
    arguments: ['lol']
})
.send({
    from: acc,
    gas: 1500000,
    gasPrice: '300000'
})
.then(function(newInstance) {
    instance = newInstance;
    return instance.methods.createPatient(12112333)
        .send({from: acc});
})
.then(function() {
    return instance.methods.updatePatient(12112333,"aa",1,2,"abb")
        .send({from: acc});
})
.then(function() {
    return instance.methods.getbirth(123112333).call({from: acc});
})
.then(function(result) {
    console.log(result);
})
.catch(function(err) {
    console.log(err);
});
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.