After launching Truffle in the "(develop)" view, I've tried to connect to it through Metamask (via the "Custom RPC" option in the "Networks" menu, I've set the URI to "").

Then, I've tried to import into Metamask the mnemonic phrase that Truffle gave me upon launching, but this gave me access to only 2 of the 10 accounts that Truffle created. Also, those 2 accounts don't have a balance of 100 ETH (as they should): the first account has a balance which changes costantly, but never goes below 200k ETH or above 260k ETH, while the other account has always a balance of 0 ETH.

Furthermore, interactions through a simple web-app that I've created for testing purposes don't seem to change the state of the corresponding smart contract or the amount of ether assigned to the first account, which makes me think that my web browser isn't correctly communicating with the local instance provided by Truffle. What piece of the puzzle am I missing?

EDIT: Here's the significant snippets of code of the web-app (I'm using web3 API in React).

function App() {

  const [web3] = useState(new Web3(Web3.givenProvider || "http://localhost:9545"));
  const [contract] = useState(new web3.eth.Contract(TODO_ABI, TODO_ADDRESS));
  const [tasks, setTasks] = useState([]);

  useEffect(() => {

      .then(tasks => {


  }, [contract.methods]);

  return (
    <div className="container">
      <TaskForm contract={contract}></TaskForm>
      <TasksList tasks={tasks} contract={contract}></TasksList>

function TaskForm(props) {

  const [content, setContent] = useState("");

    <form onSubmit={ () => setContent(event.target.value) }>
      <input type="text" onChange={ () => props.contract.methods.addTask(content).call() }></input>
      <button type="submit">Submit</button>

function ChangeTaskStateButton(props) {

  return (
    <button onClick={ () => props.contract.methods.changeTaskState(props.id).call() }>{ props.state }</button>

And here's the errors that gets displayed when trying to close a task:

inpage.js:1 MetaMask - RPC Error: Internal JSON-RPC error. 
{code: -32603, message: "Internal JSON-RPC error.", data: {…}}
code: -32603
data: {message: "VM Exception while processing transaction: revert", code: -32000, data: {…}}
message: "Internal JSON-RPC error."
__proto__: Object

index.js:50 Uncaught (in promise) Error: Internal JSON-RPC error.
  "message": "VM Exception while processing transaction: revert",
  "code": -32000,
  "data": {
    "0x359c33ac64b2b3eb0096b40b2d225679d4212f40fc86ef938af49fcc47159f2c": {
      "error": "revert",
      "program_counter": 994,
      "return": "0x4e487b710000000000000000000000000000000000000000000000000000000000000032"
    "stack": "RuntimeError: VM Exception while processing transaction: revert\n    at Function.RuntimeError.fromResults (C:\\Users\\gianm\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\ganache-core\\lib\\utils\\runtimeerror.js:94:1)\n    at C:\\Users\\gianm\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\ganache-core\\lib\\blockchain_double.js:568:1",
    "name": "RuntimeError"
    at Object._fireError (index.js:50)
    at sendTxCallback (index.js:540)
    at cb (util.js:689)
    at callbackifyOnRejected (util.js:666)
    at Item.push../node_modules/process/browser.js.Item.run (browser.js:153)
    at drainQueue (browser.js:123)
  1. You can import 10 accounts by Private Key.
  2. Check your port, shouldn't the default be 8545?
  3. ETH balance display error: need to 'Settings - Network - Symbol' to fill in the ETH, although it is optional, but need to fill in the ETH
  • Solved the balance problem, so that's good. However, my webapp still doesn't seem to be communicating properly with my contract. Right after executing "truffle develop", I get the message "Truffle Develop started at". Also, connection attempts to port 8545 are unsuccessful anyway. What's weird is that my app allows for two types of transactions: 1) adding a new task to the list corresponding to the address currently in use, 2) closing a task (I've added the code to the first post). Adding a task SEEMS like it's working:
    – Gian
    Jun 16 '21 at 12:34
  • it doesn't cause any error to appear in the browser's console and the task then gets displayed on the page. However, the balance of the account that requested the transaction doesn't change, and checking the tasks list of the corresponding address in the smart contract reveals that it is still empty. Conversely, closing a task just flat out doesn't work and causes two errors to be displayed in the browser's console (added those to the first post as well).
    – Gian
    Jun 16 '21 at 12:34
  • Maybe there is something wrong with the contract
    – zmy
    Jun 18 '21 at 9:09
  • I doubt it, It compiles successfully and when I interact with it through the truffle develop console, it works exactly as intended. I very much think it is a clientside problem. I just can't figure out what problem it is. I checked out a bunch of basic dapp tutorials to see if I did something wrong, but they all do what I did, I'm pretty confused. I even tried using a different browser, but nothing. I'm really weirded out, especially because the calls to the contract that I use to retrieve the tasks and to add a new task don't cause any errors to be diplayed, they just silently don't work
    – Gian
    Jun 19 '21 at 7:33
  • 1
    Come on, we make progress together!
    – zmy
    Jun 23 '21 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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