我正在尝试使用以下代码调用ERC20合同的转让。我的环境是Geneche-cli和安装了Web3的Node。该应用程序是控制台,但稍后将在Web应用程序中使用此功能。请给我一些如何处理的提示。这是函数,然后调用此函数,我在结尾处出现了错误
代码------------- sendTokens:function(fromAddress,sendAddress,amountToSend,abi,contractAddress,web3Address){
return new Promise(function(resolve, reject) {
var web3 = new Web3(new Web3.providers.HttpProvider(web3Address));
if(web3.isConnected()) {
var count = web3.eth.getTransactionCount(fromAddress);
var contract = web3.eth.contract(abi).at(contractAddress);
var rawTransaction = {
"from": fromAddress,
"nonce": web3.toHex(count+1),
"gasPrice": "0x04e3b29200",
"gasLimit": "0x7458",
"to": contractAddress,
"value": "0x0",
"data": contract.transfer(sendAddress, 10, {from: fromAddress}),
"chainId": 0x03
};
var privKey = new Buffer.from('c0270793c6d211618dbef578aa380e744547e417e21fb295235ee2d4c94cd04e', 'hex');
var tx = new ethereumjs(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
if (!err)
console.log(hash);
else
console.log(err);
});
} else {
resolve({"code":"0", "message":"connection error"})
}
})
},
这是错误
Error: VM Exception while processing transaction: revert
at Object.InvalidResponse (F:\Projects\work\GS\BlockchainSettings\node_modules\web3\lib\web3\errors.js:38:16)
at F:\Projects\work\GS\BlockchainSettings\node_modules\web3\lib\web3\requestmanager.js:86:36
at XMLHttpRequest.request.onreadystatechange (F:\Projects\work\GS\BlockchainSettings\node_modules\web3\lib\web3\httpprovider.js:129:7)
at XMLHttpRequestEventTarget.dispatchEvent (F:\Projects\work\GS\BlockchainSettings\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (F:\Projects\work\GS\BlockchainSettings\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (F:\Projects\work\GS\BlockchainSettings\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (F:\Projects\work\GS\BlockchainSettings\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)