-1

我需要在 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>
4

1 回答 1

0

对不起,低代表,否则我会评论:您可能需要签署交易。在以太坊上发送数据与查看数据不同。特别是如果您没有使用像元掩码这样的东西作为您的提供者(您使用的是本地主机),您将不得不手动签署交易。

另外我不确定这是否是一次性钱包,但永远不要发布你的私钥!

于 2019-06-18T19:26:24.530 回答