0

I am trying to develop a Dapp with nodejs backend but I cannot get accounts from Metamask which resides on my frontend. I tried to create an endpoint for each function in Smart Contract. And it seems transaction needs to be initiated via backend. API works fine with testrpc(localhost provider) but fails when i need to connect with frontend.

This is how I created API:

async setOrganization(req, res){
    console.log("+++++adding organization++++");
    //Here certificate is contract's instance
    console.log(certificate);
    let address = req.body.address;
    let name = req.body.name;
    let doe = req.body.doe;
    let pan = req.body.pan;
    await certificate.setOrganization(address, name, doe,pan, {
        from:web3.eth.accounts[0],gas:300000
    }).then((result)=>{
        res.send(result);
    }).catch((e) => {
        console.log("Error Occurred",e);
        res.json({
            logs: e.message,
            status: false
        });
    });
}

here in the code above, I cannot get metamask account from web3.eth.accounts[0].

Your Answer

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

Browse other questions tagged or ask your own question.