I am new to using function app as well as JS. Below is what i am trying to do :
- we have a internal quorum cluster using Azure blockchain service. we have deployed a contract on it and need to check the events for this contract. And in general, want to interact with this contract.
- For interacting with this contract, we plan to use a node js app which will be hosted using Azure Function app.
- I have created a test script which creates contract instance and logs the output of getpastevents method.
The script is working fine on my local node setup but on function app, the execution does not wait for the promise to finish and capture the final result. Rather, it just logs 'promise pending' and moves on.
please ignore the myBlob input, i am just testing this function in a Blob trigger. code :
module.exports = async function (context, myBlob) {
context.log("JavaScript blob trigger function processed blob \n Blob:", context.bindingData.blobTrigger, "\n Blob Size:", myBlob.length, "Bytes");
var Web3 = require('web3')
const rpcURL = "https://<myapp>.blockchain.azure.com:port/key"
const web3 = new Web3(rpcURL)
const account = <validAccount>
var privateKey = Buffer.from(<validkey>, 'hex')
var abi=,Validabi>
var contractAddress=<contractaddress>;
var contract = new web3.eth.Contract(abi, contractAddress);
contract.getPastEvents('allEvents', {fromBlock : 0, toBlock :'latest'}).then((events) => { result = events;
context.log(result)}).catch((error)=>{context.log('error')});
};