Conflux-Chain / conflux-portal

:globe_with_meridians: :electric_plug: The ConfluxPortal browser extension enables browsing Conflux blockchain enabled websites.
https://conflux-chain.github.io/conflux-portal-docs
MIT License
69 stars 17 forks source link

Signing with localhost:12537 inexplicably changes txns from net999 to net2999 (?) #352

Open DanBurton opened 2 years ago

DanBurton commented 2 years ago

Describe the bug When I attempt to sign & send a transaction using the built-in network settings for Localhost 12537, after clicking "confirm", it fails to sign the transaction with an error about "net2999", even though the to/from addresses in my transaction are both "net999".

To Reproduce

<html>
<head>
<script type="text/javascript">
async function transfer(from, to, value) {
  value = '0x' + BigInt(value).toString(16)
  console.log({from, to, value});
  return new Promise((resolve, reject) => {
    conflux.sendAsync({
      method: 'cfx_sendTransaction',
      params: [{from, to, value}],
      from,
      value,
    }, (err, data) => {
      if (err) { reject(err); } else { resolve(data); }
    })
  });
}

async function go () {
  const from = (await conflux.enable())[0];
  const to = document.getElementById('to').value || from; // default: send to self
  const amt = parseInt(document.getElementById('amt').value) || 10; // CFX
  const value = amt + '0'.repeat(18); // Drip

  await transfer(from, to, value);
}
</script>
</head>
<body>
  <input id="amt" type="number" value=10 style="width: 3em" /> CFX
  to <input id="to" placeholder="paste address here" />
  <button onClick="go()">Send</button>
</body>
</html>

Expected behavior sendAsync should transfer the funds on the devnet running at localhost:12537. (It works on TestNet.)

Browser details (please complete the following information):

Additional context

Sometimes it will not let you click Confirm, claiming that there is no balance (even on accounts with a balance on your localhost devnet.) Other times, it will fail with the following error:

ConfluxPortal - RPC Error: Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"message":"Invalid parameters: address","data":"\"network prefix unexpected: ours net999, got net2999\"","stack":"Error: Invalid parameters: address\n    at s (chrome-extension://opafkgfpaamecojfkaialabagfofilmg/background.js:1:398023)\n    at Object.internal (chrome-extension://opafkgfpaamecojfkaialabagfofilmg/background.js:1:398412)\n    at l (chrome-extension://opafkgfpaamecojfkaialabagfofilmg/background.js:1:393516)\n    at chrome-extension://opafkgfpaamecojfkaialabagfofilmg/background.js:1:392727"}}' 

This is nonsense. See the output of the console.log included in the html snippet above, which will indicate that the transaction being sent is for net999 as it should be.

DanBurton commented 2 years ago

Note that if you create a "custom rpc" network option, and point it at 127.0.0.1:12537 (it will not allow you to do localhost:12537), then everything works as expected. I have no idea why the built-in localhost:12537 settings are misbehaving.