Web3js

呼叫 setFoo() 函式時出現無效地址錯誤

  • August 3, 2018

我的混音

pragma solidity ^0.4.24;

contract Foo {
   bytes32 foo;

   function setFoo(bytes32 _foo) public {
       foo = _foo;
   }

   function getFoo() public constant returns (bytes32) {
       return foo;
   }
}

我的腳本

var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
web3.eth.defaultAccounbt = web3.eth.accounts[0];

var fooContract = web3.eth.contract([{
   "constant": true,
   "inputs": [],
   "name": "getFoo",
   "outputs": [{
     "name": "",
     "type": "bytes32"
   }],
   "payable": false,
   "stateMutability": "view",
   "type": "function"
 },
 {
   "constant": false,
   "inputs": [{
     "name": "_foo",
     "type": "bytes32"
   }],
   "name": "setFoo",
   "outputs": [],
   "payable": false,
   "stateMutability": "nonpayable",
   "type": "function"
 }
]);

var foo = fooContract.at('0xe884fb988c3242bcd16a0e187b10e6261733477e');

我的 chrome 控制台

foo.setFoo("hello world");

問題可能只是這個錯字:

web3.eth.defaultAccounbt = web3.eth.accounts[0];

(Account b t中的一個流浪“b” )

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