Search code examples
javascriptethereumsoliditysmartcontracts

How to interact with my smart contract on web browser


I deployed my contract on ropsten.
And I tried to interact with it on browser but error message said that it is not a function.
I already tried at NodeJS and there was no error. So the contract address or ABI file isn't wrong.

This is my code. Is there an error here?

const address = 'Contract addresss';
const myContract = new web3.eth.Contract(ABI, address);
let result = await myContract.methods.createDoc('asdf').call();
console.log(result);

Solution

  • Try changing this line

    let result = await myContract.methods.createDoc('asdf').call();
    

    To either one of these:

    let result = await myContract.methods.createDoc().call('asdf');
    
    let result = await myContract.methods.createDoc('asdf');