ここでは、tronWebを使用して、スマートコントラクトの買掛金変更メソッドを呼び出し、転送を実現する方法を示します。
TRON契約コード
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メソッドを呼び出します
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-web
ブロガーを好きになることを忘れないでください