Web3js

UnhandledPromiseRejectionWarning:錯誤:返回錯誤:方法 eth_sendTransaction 不存在/不可用

  • May 8, 2020
var Web3 = require('web3')

var url = 'https://rinkeby.infura.io/v3/cadc6b0dc5c54720b973b3720eab5584' 

var web3 = new Web3(url)




var RemixContract = new web3.eth.Contract([
   {
       "constant": false,
       "inputs": [
           {
               "name": "x",
               "type": "string"
           }
       ],
       "name": "setMessage",
       "outputs": [],
       "payable": false,
       "stateMutability": "nonpayable",
       "type": "function"
   },
   {
       "constant": true,
       "inputs": [],
       "name": "getMessage",
       "outputs": [
           {
               "name": "",
               "type": "string"
           }
       ],
       "payable": false,
       "stateMutability": "view",
       "type": "function"
   }
],'0x7Cad41DAc15e54051c387895541875B46932fa09',{from:'0x84809AC58F7476Ba7A6F8BF2C66896d0fa59F6f6'});


RemixContract.methods.setMessage("Again").send()

這是我的契約

pragma solidity ^0.4.24;

contract Message {
   string myMessage;

   function setMessage(string x) public {
       myMessage = x;
   }

   function getMessage() public view returns (string) {
       return myMessage;
   }
}

這不是您可以連接到 infura 的方式。更改此程式碼

var url = 'https://rinkeby.infura.io/v3/cadc6b0dc5c54720b973b3720eab5584' 

var web3 = new Web3(url)

使用此程式碼

const url = new Web3.providers.HttpProvider(
   'https://rinkeby.infura.io/v3/cadc6b0dc5c54720b973b3720eab5584'
 );
web3 = new Web3(url);

此外,您最好將您的 Solidity 程式碼更新到最新版本。

引用自:https://ethereum.stackexchange.com/questions/83179