«this._eth.sendTransaction не является функцией» при выполнении метода в Web3

Я использую react-web3 (который в основном возвращает мне объект web3), и я пытаюсь заставить свой контракт работать. Это код, который я использую:

const web3 = window.web3;
    const contract = new web3.eth.contract(ABI.abi).at("0xdbb05ed3b5acb77cbd2366d037fe051703958dac");
    contract.buyTicket.sendTransaction(3000, {
        from: '0x5c1a92217e456a7eB4a051B567FC751A534991a3',
        value: web3.toWei(1, 'ether')
    });

От — мой адрес по умолчанию в MetaMask.

Мой контракт:

"abi": [
    {
      "constant": false,
      "inputs": [],
      "name": "restartLottery",
      "outputs": [],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "myid",
          "type": "bytes32"
        },
        {
          "name": "result",
          "type": "string"
        }
      ],
      "name": "__callback",
      "outputs": [],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [],
      "name": "toggleActive",
      "outputs": [],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "myid",
          "type": "bytes32"
        },
        {
          "name": "result",
          "type": "string"
        },
        {
          "name": "proof",
          "type": "bytes"
        }
      ],
      "name": "__callback",
      "outputs": [],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [],
      "name": "getTotalPotSize",
      "outputs": [
        {
          "name": "",
          "type": "uint256"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "_estimate",
          "type": "uint256"
        }
      ],
      "name": "buyTicket",
      "outputs": [
        {
          "name": "",
          "type": "uint256"
        }
      ],
      "payable": true,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [],
      "name": "getActiveState",
      "outputs": [
        {
          "name": "",
          "type": "bool"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [],
      "name": "getKrakenPrice",
      "outputs": [],
      "payable": true,
      "type": "function"
    },
    {
      "constant": true,
      "inputs": [],
      "name": "owner",
      "outputs": [
        {
          "name": "",
          "type": "address"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "_gameId",
          "type": "uint256"
        }
      ],
      "name": "getEstimationPerGame",
      "outputs": [
        {
          "name": "",
          "type": "uint256"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "_gameId",
          "type": "uint256"
        }
      ],
      "name": "getBuyersPerGame",
      "outputs": [
        {
          "name": "",
          "type": "uint256"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "inputs": [],
      "payable": false,
      "type": "constructor"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": false,
          "name": "price",
          "type": "uint256"
        }
      ],
      "name": "estimateAndPayout",
      "type": "event"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": false,
          "name": "price",
          "type": "uint256"
        }
      ],
      "name": "priceRetrieved",
      "type": "event"
    }
  ],

Я продолжаю получать эту ошибку:

Uncaught TypeError: this._eth.sendTransaction is not a function
    at c.sendTransaction (inpage.js:8253)
    at test (Landingpage.jsx:22)
    at Landingpage.componentDidMount (Landingpage.jsx:46)
    at ReactCompositeComponent.js:264
    at measureLifeCyclePerf (ReactCompositeComponent.js:75)
    at ReactCompositeComponent.js:263
    at CallbackQueue.notifyAll (CallbackQueue.js:76)
    at ReactReconcileTransaction.close (ReactReconcileTransaction.js:80)
    at ReactReconcileTransaction.closeAll (Transaction.js:209)
    at ReactReconcileTransaction.perform (Transaction.js:156)
    at batchedMountComponentIntoNode (ReactMount.js:126)
    at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:143)
    at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
    at Object.batchedUpdates (ReactUpdates.js:97)
    at Object._renderNewRootComponent (ReactMount.js:319)
    at Object._renderSubtreeIntoContainer (ReactMount.js:401)
    at Object.render (ReactMount.js:422)
    at Object../src/index.js (index.js:34)
    at __webpack_require__ (bootstrap 2d91de1…:659)
    at fn (bootstrap 2d91de1…:85)
    at Object.0 (web3Reducer.js:21)
    at __webpack_require__ (bootstrap 2d91de1…:659)
    at ./node_modules/ansi-regex/index.js.module.exports (bootstrap 2d91de1…:708)
    at bundle.js:712

Есть идеи?

Информация Я использую свой контракт с testrpc и развертываю его там с помощью truffle

Я не уверен, что означает _eth, так как его нет в фрагменте кода, который вы вставили. Обычно sendTranscation в web3 будет выглядеть так: this.eth.sendTransaction, где это экземпляр web3.
какую версию веб3 вы используете? Вы уверены, что это ABI.abiдает вам ABI в виде массива?
Спасибо - хороший совет :) Я использую версию "версия": "0.20.1". ABI.abi дает мне правильный массив
Я думаю, это из-за new, см. мою правку

Ответы (1)

Вам не нужно вызывать sendTransactionфункцию явно, просто вызовите функцию вашего смарт-контракта следующим образом:

contract.buyTicket(3000, {
        from: '0x5c1a92217e456a7eB4a051B567FC751A534991a3',
        gas: 1000000,
        value: web3.toWei(1, 'ether')
    });

также не забудьте указать лимит газа

редактировать : вам не нужно создавать экземпляр нового объекта с помощью new, web3 должен предоставить вам экземпляр вашего смарт-контракта:

const contract = web3.eth.contract(ABI.abi).at("0xdbb05ed3b5acb77cbd2366d037fe051703958dac");
Хммм - сообщение об ошибке остается прежним