波場tronWeb調用智能合約payable修飾的方法

這裏將展現,如何在波場使用tronWeb調用智能合約payable修飾的方法,並實現轉帳web

波場合約代碼ui

pragma solidity ^0.5.0;
//請注意這個僅是Demo,請不要用到正式環境
contract PayTest is Ownable{
	
	

    
    //向當前合約存款
    function deposit(uint256 amount)public payable {
        //msg.sender 全局變量,調用合約的發起方
        //msg.value 全局變量,調用合約的發起方轉發的貨幣量,以wei爲單位。
        //send() 執行的結果
		
         //address(this).send(amount);
		//address(this).transfer(amount);
		//lpToken.transferFrom(address(msg.sender), address(this), amount);
		
    }
	
	//取款
	function withdraw(uint256 _amount)public  {
		//owner.transfer(address(this).balance);
		msg.sender.transfer(address(this).balance/2);
		
		
	}
}

下面tronWeb調用deposit方法,實現轉帳this

const value = tronWeb.toBigNumber(amount * Math.pow(10, decimals))
  let instance = await tronWeb.contract().at(contractAddress);
  let res = await instance["deposit"](tronWeb.toHex(value.toNumber()));
  let tx=res.send({
    feeLimit:100000000,
    callValue:tronWeb.toSun(amount),
    tokenId:0,
    shouldPollResponse:true
  });
  console.log(tx)

寫這邊文章固然也參考了:https://stackoverflow.com/questions/62015095/how-to-call-payable-functions-in-tron-webcode

 

不要忘記給博主點個贊喲token

相關文章
相關標籤/搜索