0

I just deployed a contract and wants to access it using web3 to read and write data.

I have web3 working, passed the contract Address and ABI and I can access the contract and Read Data using:

contract.methods.getPrice().call()

This returns the correct value from the contract.

However, If i want to write something using send() like:

contract.methods.setTestString("Test").send( {from: account }, function(error, transactionHash){ alert(error); });

I get the error "Method not found". But the method is there and it is also public available.

Any ideas?

Thx

1
  • we need more information, like web3 version, using ganache , truffle?
    – Majd TL
    Mar 25, 2021 at 13:55

1 Answer 1

1

This code is working for my sets:

        async function setAnString() {
            var varSetAnString = await contract.methods.setAnString( "As you want" ).send()
            .then((result) => {
                    console.log("Success! Got result: " + result);
                    console.log("The value setted: "+varSetAnString);
                    let tmp = JSON.stringify(result,null,1); console.log("result::"+ tmp);
                }).catch((err) => {
                    console.log("Failed with error: " + err);
                });
        }
        setAnString();  

Be careful with the ABI. Maybe you need to update. Hope it helps.

UPDATE:

I previously declare the contract and from address in external options:

const contract = new web3js.eth.Contract(abi);

contract.options.from = '0x0.......';
contract.options.address = '0x0.......'; //Contract address

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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