Ich habe einen Mustervertrag mit einer Funktion:
pragma solidity ^0.4.0;
contract Test {
function sell(address transferTo) public {
transferTo.transfer(1000);
}
}
Ich verwende testrpc
und truffle
zum Bereitstellen und Ausführen von Verträgen:
Test.deployed().then(instance => instance.sell(accounts[1], {from: accounts[0]}))
und Befehl schlägt mit Ausnahme auf VM-Ebene fehl:
Error: VM Exception while processing transaction: revert
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:70604:12)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:70449:12)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:70159:18)
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:315621:13)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:314196:9
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:331156:36
at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43303:16)
Irgendwelche Gedanken, was schief gelaufen ist? Scheint, als ob diese Funktion darstellt, was Dokumente sagen.
Da Sie die Methode aus dem Vertrag aufrufen transfer()
, versucht sie, das Guthaben aus dem Vertrag selbst zu übertragen , anstatt die 1000 vom Aufrufer zu nehmen. Es scheitert, weil der Vertrag keinen Saldo hat.
pragma solidity ^0.4.0;
contract Test {
function sell(address transferTo)
public
payable // make function payable
{
// change the amount to the amount sent with the call (msg.value)
transferTo.transfer(msg.value);
}
}
Im Truffle-Befehl müssten Sie einen Wertbetrag für die Überweisung hinzufügen:
Test.deployed().then(instance => instance.sell(accounts[1], {from: accounts[0], value: web3.toWei(1, 'ether') }))
Carlolm
Gleichmut
Gleichmut
Carlolm
Carlolm
Gleichmut