Trc20.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. namespace TronTool;
  3. class Trc20 extends Contract{
  4. function __construct($tronApi,$credential=null){
  5. parent::__construct($tronApi,ABI_TRC20,$credential);
  6. }
  7. function transfer($to,$value){
  8. return $this->send('transfer',$to,$value);
  9. }
  10. function transferFrom($from,$to,$value){
  11. return $this->send('transferFrom',$from,$to,$value);
  12. }
  13. function approve($spender,$value){
  14. return $this->send('approve',$spender,$value);
  15. }
  16. function allowance($owner,$spender){
  17. return $this->call('allowance',$owner,$spender);
  18. }
  19. function totalSupply(){
  20. $ret = $this->call('totalSupply');
  21. return $ret[0];
  22. }
  23. function balanceOf($owner){
  24. $ret = $this->call('balanceOf',$owner);
  25. return $ret[0];
  26. }
  27. function name(){
  28. $ret = $this->call('name');
  29. return $ret[0];
  30. }
  31. function symbol(){
  32. $ret = $this->call('symbol');
  33. return $ret[0];
  34. }
  35. function decimals(){
  36. $ret = $this->call('decimals');
  37. return $ret[0];
  38. }
  39. }
  40. $erc20 = <<<WIZ
  41. [
  42. {
  43. "constant": true,
  44. "inputs": [],
  45. "name": "name",
  46. "outputs": [
  47. {
  48. "name": "",
  49. "type": "string"
  50. }
  51. ],
  52. "payable": false,
  53. "stateMutability": "view",
  54. "type": "function"
  55. },
  56. {
  57. "constant": false,
  58. "inputs": [
  59. {
  60. "name": "_spender",
  61. "type": "address"
  62. },
  63. {
  64. "name": "_value",
  65. "type": "uint256"
  66. }
  67. ],
  68. "name": "approve",
  69. "outputs": [
  70. {
  71. "name": "",
  72. "type": "bool"
  73. }
  74. ],
  75. "payable": false,
  76. "stateMutability": "nonpayable",
  77. "type": "function"
  78. },
  79. {
  80. "constant": true,
  81. "inputs": [],
  82. "name": "totalSupply",
  83. "outputs": [
  84. {
  85. "name": "",
  86. "type": "uint256"
  87. }
  88. ],
  89. "payable": false,
  90. "stateMutability": "view",
  91. "type": "function"
  92. },
  93. {
  94. "constant": false,
  95. "inputs": [
  96. {
  97. "name": "_from",
  98. "type": "address"
  99. },
  100. {
  101. "name": "_to",
  102. "type": "address"
  103. },
  104. {
  105. "name": "_value",
  106. "type": "uint256"
  107. }
  108. ],
  109. "name": "transferFrom",
  110. "outputs": [
  111. {
  112. "name": "",
  113. "type": "bool"
  114. }
  115. ],
  116. "payable": false,
  117. "stateMutability": "nonpayable",
  118. "type": "function"
  119. },
  120. {
  121. "constant": true,
  122. "inputs": [],
  123. "name": "decimals",
  124. "outputs": [
  125. {
  126. "name": "",
  127. "type": "uint8"
  128. }
  129. ],
  130. "payable": false,
  131. "stateMutability": "view",
  132. "type": "function"
  133. },
  134. {
  135. "constant": true,
  136. "inputs": [
  137. {
  138. "name": "_owner",
  139. "type": "address"
  140. }
  141. ],
  142. "name": "balanceOf",
  143. "outputs": [
  144. {
  145. "name": "balance",
  146. "type": "uint256"
  147. }
  148. ],
  149. "payable": false,
  150. "stateMutability": "view",
  151. "type": "function"
  152. },
  153. {
  154. "constant": true,
  155. "inputs": [],
  156. "name": "symbol",
  157. "outputs": [
  158. {
  159. "name": "",
  160. "type": "string"
  161. }
  162. ],
  163. "payable": false,
  164. "stateMutability": "view",
  165. "type": "function"
  166. },
  167. {
  168. "constant": false,
  169. "inputs": [
  170. {
  171. "name": "_to",
  172. "type": "address"
  173. },
  174. {
  175. "name": "_value",
  176. "type": "uint256"
  177. }
  178. ],
  179. "name": "transfer",
  180. "outputs": [
  181. {
  182. "name": "",
  183. "type": "bool"
  184. }
  185. ],
  186. "payable": false,
  187. "stateMutability": "nonpayable",
  188. "type": "function"
  189. },
  190. {
  191. "constant": true,
  192. "inputs": [
  193. {
  194. "name": "_owner",
  195. "type": "address"
  196. },
  197. {
  198. "name": "_spender",
  199. "type": "address"
  200. }
  201. ],
  202. "name": "allowance",
  203. "outputs": [
  204. {
  205. "name": "",
  206. "type": "uint256"
  207. }
  208. ],
  209. "payable": false,
  210. "stateMutability": "view",
  211. "type": "function"
  212. },
  213. {
  214. "payable": true,
  215. "stateMutability": "payable",
  216. "type": "fallback"
  217. },
  218. {
  219. "anonymous": false,
  220. "inputs": [
  221. {
  222. "indexed": true,
  223. "name": "owner",
  224. "type": "address"
  225. },
  226. {
  227. "indexed": true,
  228. "name": "spender",
  229. "type": "address"
  230. },
  231. {
  232. "indexed": false,
  233. "name": "value",
  234. "type": "uint256"
  235. }
  236. ],
  237. "name": "Approval",
  238. "type": "event"
  239. },
  240. {
  241. "anonymous": false,
  242. "inputs": [
  243. {
  244. "indexed": true,
  245. "name": "from",
  246. "type": "address"
  247. },
  248. {
  249. "indexed": true,
  250. "name": "to",
  251. "type": "address"
  252. },
  253. {
  254. "indexed": false,
  255. "name": "value",
  256. "type": "uint256"
  257. }
  258. ],
  259. "name": "Transfer",
  260. "type": "event"
  261. }
  262. ]
  263. WIZ;
  264. define('ABI_TRC20',$erc20);