Ich verwende React-Web3 (was mir im Grunde ein Web3-Objekt zurückgibt) und ich versuche, meinen Vertrag zum Laufen zu bringen. Dies ist der Code, den ich verwende:
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')
});
Der Absender ist meine Standardadresse in MetaMask.
Mein Vertrag:
"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"
}
],
Ich bekomme immer diesen Fehler:
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
Irgendeine Idee?
Info Ich nutze meinen Vertrag mit testrpc und setze ihn dort mit truffle ein
Sie müssen die sendTransaction
Funktion nicht explizit aufrufen, rufen Sie einfach die Funktion Ihres Smart-Contracts wie folgt auf:
contract.buyTicket(3000, {
from: '0x5c1a92217e456a7eB4a051B567FC751A534991a3',
gas: 1000000,
value: web3.toWei(1, 'ether')
});
Vergessen Sie auch nicht, das Gas-Limit zu definieren
Bearbeiten : Sie müssen kein neues Objekt mit new
instanziieren, web3 sollte Ihnen die Instanz Ihres Smart-Vertrags geben:
const contract = web3.eth.contract(ABI.abi).at("0xdbb05ed3b5acb77cbd2366d037fe051703958dac");
Rangesch
Sepultura
ABI.abi
Sie das ABI als Array erhalten?Fabian Lürz
Sepultura
new
, siehe meine Bearbeitung