1

I have looked alot for information about this and lastly i turn myself to here. I've written a smartcontract and deployed it to Ropsten . I am then using web3.js to interact with my smartcontract, i can use .call methods with no errors, but i have no idea how to fire methods that change the state, in this case mint, burn and send_X_tokens. From web3 docs it is stated in examples to be like this

myContract.methods.myMethod(123).send({from: 'ADDRESS'})
.then(console.log(receipt){
});

but that doesn't help me much. I assume i have to setup my account to be open or create and sign a transaction in order to use gas, but i cannot find anything on how to do that.

So thus far my code looks like this.

contract.methods.mint().send({ from: '0x76a9CEA17DbA8a371944d00a2E9A17AA3669B392', gas: 4000000 }).then(console.log(result))

And the error looks like this.

(node:28313) UnhandledPromiseRejectionWarning: Error: Returned error: The method eth_sendTransaction does not exist/is not available
    at Object.ErrorResponse (/home/ubuntu/ethereum_website/node_modules/web3-core-helpers/src/errors.js:29:16)
    at /home/ubuntu/ethereum_website/node_modules/web3-core-requestmanager/src/index.js:140:36
    at XMLHttpRequest.request.onreadystatechange (/home/ubuntu/ethereum_website/node_modules/web3-providers-http/src/index.js:96:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/ubuntu/ethereum_website/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/home/ubuntu/ethereum_website/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/home/ubuntu/ethereum_website/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/home/ubuntu/ethereum_website/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Help me solve this (probably) most basic puzzle.

3
  • Trying to reproduce your error. Oct 11, 2019 at 17:40
  • Shouldn’t you be issuing call?
    – 0xsegfault
    Oct 12, 2019 at 19:27
  • .call does not work because the "mint()" method changes the state of the smartcontract.
    – Joze Jerse
    Oct 13, 2019 at 7:36

2 Answers 2

1

The solution was to create and add the account from which to send the transaction into a wallet.

adding the line

web3.eth.accounts.wallet.add('address_private_key')

above the method.send() fixed it for me.

0

Have you defined mint function as accepting any arguments?

If so, I think you need to pass argument(s) like

myContract.methods.mint(mintAmount).send({ from: accounts[0] }) .on(“receipt”, receipt => console.log(receipt))

https://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html#methods-mymethod-send

I hope your problem will be solved

Your Answer

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

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