超级区块中的代币转移

时间:2019-04-05 09:28:11

标签: solidity web3js superblock

我正在Superblocks中开发一个Dapp,它可以将Eht从一个地址转移到另一个地址,因为Superblocks中的教程太少了。 我的智能合约代码:

contract Transfer {
address owner ; 


function Transfer() public {
   owner = msg.sender;

}
function transferTokens (address add) payable public   {


        add.transfer(msg.value);

}
function getBalance () public returns ( uint){


    return add.balance;
}

}

我的js。文件代码:

  function waitForReceipt (txHash , cb){
    alert("wait for receipt function");
    web3_instance.eth.getTransactionReceipt(txHash, function(error, receipt){
        if (error){

            alert(error);
        }
        else if (receipt != null){
            alert("receipt arrived successful");
            cb(receipt);
        }
        else (setTimeout(function(){
            alert(" timeout function ");

            waitForReceipt(txHash, cb);


        }, 5000));
    });


}

 function transfer (){
   alert("transfer function ");
   let val = parseInt($("#numOfTokens").val());
   let Address = $("#address").val();
   instance.transferTokens.sendTransaction(Address ,{from: accounts[0], 
   gas:100000, value: val}, function(error, result){
        if(error){

        alert("error");
    }
    else{
        instance.getBalance(function (err, result){

            if(!err){

                alert(result);

            }

        })

        alert("transaction success, sending txhash to wait for receipt 
        function ");

        waitForReceipt(result, function(receipt){
           alert("passed receipt trough cb function to wfr function ");
          if(receipt.status === "0x1"){






       }
       else {
            alert("receipt error...");

       }


     });
   }


   });
 }

$(document).ready(function () {
    init(function () {

    });

    $("#submit").click (function(){
        transfer();

    });
});
})(Contracts['Transfer']);

我输入的地址没有得到我想转移到该地址的金额,有人收到建议吗?

0 个答案:

没有答案