我需要在localhost中测试erc20令牌事务。为此,我使用rpc在终端上运行了Etherium钱包。我有一个未知地址错误。下面是我的代码。
我在脚本中直接提供了所有详细信息,例如合同地址,其他地址。我正在使用web3js。
<?php
$abi_get=file_get_contents('https://api.etherscan.io/api?module=contract&action=getabi&address=0xf5e7f08c91b5d8579746eaad70ac509e94e2f1d3&apikey=5N8DNJPJJH5J7X7IN3VHSBBCHDIE9SV3GA');
$abi_result = json_decode($abi_get,true);
$abi=$abi_result['result'];
?>
<script src="<?php echo js_url();?>/web3.min.js"></script>
<script>
transfer();
var http = require('http');
var Web3 = require('web3');
var Tx = require('ethereumjs-tx');
var Bf=require('Buffer');
function transfer()
{
//var Web3 = require("web3");
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8585"));
}
//var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var from_address = "0x26650Af2BF9093A32e0E8361F89dB1e7B7609442";
var toAddress = "0xabef6c10571f45ceaf245dddf98894527c87677f";
var value = 10;
var abiArray = <?php echo $abi; ?>;
var contractAddress = "0xf5e7f08c91b5d8579746eaad70ac509e94e2f1d3";
var contract = web3.eth.contract(abiArray).at(contractAddress);
var bal=web3.fromWei(contract.balanceOf(from_address),"ether");
console.log(bal);
var trans=contract.transfer(toAddress,web3.toWei(1,"ether"),{from:from_address});
var rawTransaction = {
"from": from_address,
"nonce": web3.toHex(count),
"gasPrice": "0x04e3b29200",
"gasLimit": "0x7458",
"to": contractAddress,
"value": "0x0",
"data": contract.transfer.getData(toAddress, 10, {from: from_address}),
"chainId": 0x03
};
var privKey = new Buffer('83c737e4e5030e1fe3a2ed4762147cf9d9da80132d904d424460ed41d4591afd', 'hex');
var tx = new Tx(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);
});
}
</script>
答案 0 :(得分:0)
对不起,低代表或我会评论: 您可能需要签署交易。在etherium上发送数据与查看数据不同。具体来说,如果您未使用Metamask之类的提供程序(您正在使用本地主机),则必须手动签署交易。
我也不确定这是否是可丢弃的钱包,但是永远不要发布您的私钥!