简体   繁体   中英

Getting error while performing web3 transaction from chrome extention

I am able to retrieve data from block-chain with chrome extension but error is coming when updating some block from chrome extension.

using below code for performing transaction.

chrome.extension.onRequest.addListener(async function(request, sender, sendResponse) {
if (request.method === "getHTML") {
  console.log("Hello From react 2");
  console.log(request.data);
  const ads = await userAbi.methods.setSpecificUserClickStatistics(request.data).send({from: "some address"});
  console.log(ads);
}
});

Success output when run console.log(web3.currentProvider) connected with Web3.

   HttpProvider {host: "https://rinkeby.infura.io/<specific token>", timeout: 0, connected: false, headers: undefined}
connected:true
headers:undefined
host:"https://rinkeby.infura.io/<specific token>"
timeout:0
event.js:24170 Hello From react 2

Error which I am getting :-

event.js:60196 POST https://rinkeby.infura.io/(specific token) 405 ()
HttpProvider.send @ event.js:60196
RequestManager.send @ event.js:50121
sendRequest @ event.js:8961
(anonymous) @ event.js:8978
sendTxCallback @ event.js:8885
(anonymous) @ event.js:50136
request.onreadystatechange @ event.js:60186
XMLHttpRequest.send (async)
HttpProvider.send @ event.js:60196
RequestManager.send @ event.js:50121
sendRequest @ event.js:8961
send @ event.js:8982
send @ event.js:8973
_executeMethod @ event.js:56098
(anonymous) @ event.js:24172
EventImpl.dispatchToListener @ extensions::event_bindings:403
publicClassPrototype.(anonymous function) @ extensions::utils:138
EventImpl.dispatch_ @ extensions::event_bindings:387
EventImpl.dispatch @ extensions::event_bindings:409
publicClassPrototype.(anonymous function) @ extensions::utils:138
messageListener @ extensions::messaging:240
EventImpl.dispatchToListener @ extensions::event_bindings:403
publicClassPrototype.(anonymous function) @ extensions::utils:138
EventImpl.dispatch_ @ extensions::event_bindings:387
EventImpl.dispatch @ extensions::event_bindings:409
publicClassPrototype.(anonymous function) @ extensions::utils:138
dispatchOnMessage @ extensions::messaging:392
event.js:49362 Uncaught (in promise) Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (event.js:49362)
    at XMLHttpRequest.request.onreadystatechange (event.js:60182)
InvalidResponse @ event.js:49362
request.onreadystatechange @ event.js:60182
async function (async)
(anonymous) @ event.js:24168
EventImpl.dispatchToListener @ extensions::event_bindings:403
publicClassPrototype.(anonymous function) @ extensions::utils:138
EventImpl.dispatch_ @ extensions::event_bindings:387
EventImpl.dispatch @ extensions::event_bindings:409
publicClassPrototype.(anonymous function) @ extensions::utils:138
messageListener @ extensions::messaging:240
EventImpl.dispatchToListener @ extensions::event_bindings:403
publicClassPrototype.(anonymous function) @ extensions::utils:138
EventImpl.dispatch_ @ extensions::event_bindings:387
EventImpl.dispatch @ extensions::event_bindings:409
publicClassPrototype.(anonymous function) @ extensions::utils:138
dispatchOnMessage @ extensions::messaging:392

Any help will be a great help.

can you try these :

  1. Try to check if testrpc is running or is it stopped.
  2. Also, can you try to use http instead of https

One of these might do the trick from my exp. The first of course is for running the envt and in case of the second, it sometimes doesnt allow you to connect to the node.

Hope this helps. Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM