I'm new in solidity and I'd like to have a little bit of debug.
this is my simple example (I'm using web3 1.0)
I have a simple function in my contract
function bar(address _address_usr) public {
uint res = 5;
emit foo('test',res);
}
And I have test about it
.....
it("...", async () => {
let livello = await instance.methods.bar(accounts[0]).call();
instance.events.foo(function (error, event) {
console.log(event);
})
.on('data', function (event) {
console.log("OK");
console.log(event);
})
.on('changed', function (event) {
console.log("OK");
})
.on('error', console.error);
});
....
I'd like to know the result of res. I tried with event but I have this error
err Error: The current provider doesn't support subscriptions: HttpProvider
Can I print some result/var in my console like console.log or something like that?
Thanks
UPDATE
My web3 istance
helpers.js
const Web3 = require("web3") // import web3 v1.0 constructor
// use globally injected web3 to find the currentProvider and wrap with web3 v1.0
const getWeb3 = () => {
const myWeb3 = new Web3(web3.currentProvider)
return myWeb3
}
// assumes passed-in web3 is v1.0 and creates a function to receive contract name
const getContractInstance = (web3) => (contractName) => {
const artifact = artifacts.require(contractName) // globally injected artifacts helper
const deployedAddress = artifact.networks[artifact.network_id].address
const instance = new web3.eth.Contract(artifact.abi, deployedAddress)
return instance
}
module.exports = { getWeb3, getContractInstance }
my test.js
const {getWeb3, getContractInstance} = require("./helpers")
const web3 = getWeb3()
const getInstance = getContractInstance(web3)