一、安装需求

AAA.com
bbb.com
ccc.com

需要三个域名

1、安装环境
a.服务器 centos7以上

//软件商店
b.nginx1.2以上
c.php7.3版本

c1.安装php扩展redis和gmp
c2.删除所有php禁用函数(宝塔的软件商店,点击php设置,禁用函数,点击删除)
d.mysql5.7 + phpMyAdmin
e.redis6.26 或者reids5+
1.设置redis密码(如果不设置REDIS_PASSWORD=)

环境配置完成,即可上线程序。

调用TRC20合约的approve函数授权代币使用权给其他地址

2、HTTP API :

demo:向某个wallet/triggersmartcontractcurl -X POST https://127.0.0.1:8090/wallet/triggersmartcontract -d '{"contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182","function_selector":"approve(address,uint256)","parameter":"0000000000000000000000410FB357921DFB0E32CBC9D1B30F09AAD13017F2CD0000000000000000000000000000000000000000000000000000000000000064","fee_limit":100000000,"call_value":0,"owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB"}'

3、实现功能与页面:

下载链接:网盘下载

二、调用TRC20合约的transferFrom函数实现转账,配合approve方法使用

JAVA Tronweb示例:

const TronWeb = require('tronweb')const HttpProvider = TronWeb.providers.HttpProvider;const fullNode = new HttpProvider("https://127.0.0.1:8090");const solidityNode = new HttpProvider("https://127.0.0.1:8090");const eventServer = new HttpProvider("https://127.0.0.1:8090");const privateKey = "your private key";const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,privateKey);async function triggerSmartContract() {// Address B transfers 10 USDT from address A to C: B calls transferFrom (A, C, 10)const trc20ContractAddress = "TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK";//contract addresstry {let contract = await tronWeb.contract().at(trc20ContractAddress);//Use send to execute a non-pure or modify smart contract method on a given smart contract that modify or change values on the blockchain.// These methods consume resources(bandwidth and energy) to perform as the changes need to be broadcasted out to the network.await contract.transferFrom("TM2TmqauSEiRf16CyFgzHV2BVxBej...", //address _from"TVDGpn4hCSzJ5nkHPLetk8KQBtwaT...", //address _to100000 //amount).send({feeLimit: 10000000}).then(output => {console.log('- Output:', output, '\n');});} catch(error) {console.error("trigger smart contract error",error)}}

下载页面