天天看点

火币链 转账

 //普通转账

    transfer: async function () {

var fromAccount = this.accounts+"";

var toAccount ="0x4d39db1007A1cf15078D9d0e3e7f8E30c00d2bC6";

 var amount =this.web3.utils.toWei("0.1", 'ether') //判断钱包余额是否足够。husd位数不一样

if (this.web3.utils.isAddress(fromAccount) && this.web3.utils.isAddress(toAccount)) {

    console.log("开始转账");

//https://blog.csdn.net/ffzhihua/article/details/81126932

var myContract = new this.web3.eth.Contract(this.$aa.abiToken, this.$aa.contractAddressUSDT);

// 代币转账

  myContract.methods.transfer(toAccount, amount).send({from: fromAccount})

.on('transactionHash', function(hash){

   console.log(hash);

})

.on('receipt', function(receipt){

    console.log(receipt.status);

})

.on('confirmation', function(confirmationNumber, receipt){

   console.log(receipt.status+";getReward.confirmation="+confirmationNumber);

   })

.on('error', console.error); // If a out of gas error, the second parameter is the receipt.

    }

    },

    //转账 ht

    sendTransactionHT: async function () {

      //  这里使用Metamask 给的gas Limit 及 gas 价

 var fromAccount = this.accounts+"";

var toAccount ="0x4d39db1007A1cf15078D9d0e3e7f8E30c00d2bC6";

 var amount ="0.1";

  this.getBalance();

 console.log("转账fromAccount=" + fromAccount);

// 对输入的数字做一个检查

if (this.web3.utils.isAddress(fromAccount) && this.web3.utils.isAddress(toAccount)) {

    console.log("开始转账");

    var message = {from: fromAccount, to:toAccount, value: this.web3.utils.toWei(amount, 'ether')};

//https://blog.csdn.net/ffzhihua/article/details/81126932

    // this.web3.eth.sendTransaction(message, (err, res) => {

    //     var output = "";

    //     if (!err) {

    //         output += res;

    //         //alert("转账成功!");

    //     } else {

    //         output = "Error";

    //     }

    //     console.log("转账结果="+output)

    // });

    this.web3.eth.sendTransaction(message)

.on('transactionHash', function(hash){

   console.log(hash);

})

.on('receipt', function(receipt){

    console.log(receipt.status);

})

.on('confirmation', function(confirmationNumber, receipt){

   console.log(receipt.status+";getReward.confirmation="+confirmationNumber);

   })

.on('error', console.error); // If a out of gas error, the second parameter is the receipt.

    }

    },

继续阅读