tp5 *** 作web3

tp5  *** 作web3,第1张

composer 引入

composer require kgs/web3 'dev-master'

合约 *** 作

//查询代币余额
$coin_info = [
	'host'=>'节点',
	'abi'=>'对应合约abi',
	'address'=>'对应合约地址',
];
$web = new Web3($coin_info['host']);
$contract = Contract::at($web,$coin_info['abi'],$coin_info['address']);
$s = $contract->call('balanceOf',[$address]);

//代币转账
$web = new Web3($coin_info['host']);
$wallet = Wallet::createByPrivate($keyPrivate); //私钥
$contract = Contract::at($web,$coin_info['abi'],$coin_info['address']);
$reStr = $contract->send($wallet,'transfer',[$to,$money]);//转账地址 和 数量 注意数量单位

//查询hash状态
 $web3 = new Web3($host);
 $e = $web3->getTransactionReceipt($hash);        

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/1319838.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-11
下一篇 2022-06-11

发表评论

登录后才能评论

评论列表(0条)

保存