├── ERC20.json ├── ERC721.json ├── README.md ├── UNIV2Router.json ├── composer.json ├── composer.lock ├── erc20.php ├── exampleBase.php ├── nft.php ├── swap.php ├── swap_tokens.php ├── tx.php └── utils.php /ERC20.json: -------------------------------------------------------------------------------- 1 | { 2 | "_format": "hh-sol-artifact-1", 3 | "contractName": "ERC20", 4 | "sourceName": "contracts/token/ERC20/ERC20.sol", 5 | "abi": [ 6 | { 7 | "inputs": [ 8 | { 9 | "internalType": "string", 10 | "name": "name_", 11 | "type": "string" 12 | }, 13 | { 14 | "internalType": "string", 15 | "name": "symbol_", 16 | "type": "string" 17 | } 18 | ], 19 | "stateMutability": "nonpayable", 20 | "type": "constructor" 21 | }, 22 | { 23 | "anonymous": false, 24 | "inputs": [ 25 | { 26 | "indexed": true, 27 | "internalType": "address", 28 | "name": "owner", 29 | "type": "address" 30 | }, 31 | { 32 | "indexed": true, 33 | "internalType": "address", 34 | "name": "spender", 35 | "type": "address" 36 | }, 37 | { 38 | "indexed": false, 39 | "internalType": "uint256", 40 | "name": "value", 41 | "type": "uint256" 42 | } 43 | ], 44 | "name": "Approval", 45 | "type": "event" 46 | }, 47 | { 48 | "anonymous": false, 49 | "inputs": [ 50 | { 51 | "indexed": true, 52 | "internalType": "address", 53 | "name": "from", 54 | "type": "address" 55 | }, 56 | { 57 | "indexed": true, 58 | "internalType": "address", 59 | "name": "to", 60 | "type": "address" 61 | }, 62 | { 63 | "indexed": false, 64 | "internalType": "uint256", 65 | "name": "value", 66 | "type": "uint256" 67 | } 68 | ], 69 | "name": "Transfer", 70 | "type": "event" 71 | }, 72 | { 73 | "inputs": [ 74 | { 75 | "internalType": "address", 76 | "name": "owner", 77 | "type": "address" 78 | }, 79 | { 80 | "internalType": "address", 81 | "name": "spender", 82 | "type": "address" 83 | } 84 | ], 85 | "name": "allowance", 86 | "outputs": [ 87 | { 88 | "internalType": "uint256", 89 | "name": "", 90 | "type": "uint256" 91 | } 92 | ], 93 | "stateMutability": "view", 94 | "type": "function" 95 | }, 96 | { 97 | "inputs": [ 98 | { 99 | "internalType": "address", 100 | "name": "spender", 101 | "type": "address" 102 | }, 103 | { 104 | "internalType": "uint256", 105 | "name": "amount", 106 | "type": "uint256" 107 | } 108 | ], 109 | "name": "approve", 110 | "outputs": [ 111 | { 112 | "internalType": "bool", 113 | "name": "", 114 | "type": "bool" 115 | } 116 | ], 117 | "stateMutability": "nonpayable", 118 | "type": "function" 119 | }, 120 | { 121 | "inputs": [ 122 | { 123 | "internalType": "address", 124 | "name": "account", 125 | "type": "address" 126 | } 127 | ], 128 | "name": "balanceOf", 129 | "outputs": [ 130 | { 131 | "internalType": "uint256", 132 | "name": "", 133 | "type": "uint256" 134 | } 135 | ], 136 | "stateMutability": "view", 137 | "type": "function" 138 | }, 139 | { 140 | "inputs": [], 141 | "name": "decimals", 142 | "outputs": [ 143 | { 144 | "internalType": "uint8", 145 | "name": "", 146 | "type": "uint8" 147 | } 148 | ], 149 | "stateMutability": "view", 150 | "type": "function" 151 | }, 152 | { 153 | "inputs": [ 154 | { 155 | "internalType": "address", 156 | "name": "spender", 157 | "type": "address" 158 | }, 159 | { 160 | "internalType": "uint256", 161 | "name": "subtractedValue", 162 | "type": "uint256" 163 | } 164 | ], 165 | "name": "decreaseAllowance", 166 | "outputs": [ 167 | { 168 | "internalType": "bool", 169 | "name": "", 170 | "type": "bool" 171 | } 172 | ], 173 | "stateMutability": "nonpayable", 174 | "type": "function" 175 | }, 176 | { 177 | "inputs": [ 178 | { 179 | "internalType": "address", 180 | "name": "spender", 181 | "type": "address" 182 | }, 183 | { 184 | "internalType": "uint256", 185 | "name": "addedValue", 186 | "type": "uint256" 187 | } 188 | ], 189 | "name": "increaseAllowance", 190 | "outputs": [ 191 | { 192 | "internalType": "bool", 193 | "name": "", 194 | "type": "bool" 195 | } 196 | ], 197 | "stateMutability": "nonpayable", 198 | "type": "function" 199 | }, 200 | { 201 | "inputs": [], 202 | "name": "name", 203 | "outputs": [ 204 | { 205 | "internalType": "string", 206 | "name": "", 207 | "type": "string" 208 | } 209 | ], 210 | "stateMutability": "view", 211 | "type": "function" 212 | }, 213 | { 214 | "inputs": [], 215 | "name": "symbol", 216 | "outputs": [ 217 | { 218 | "internalType": "string", 219 | "name": "", 220 | "type": "string" 221 | } 222 | ], 223 | "stateMutability": "view", 224 | "type": "function" 225 | }, 226 | { 227 | "inputs": [], 228 | "name": "totalSupply", 229 | "outputs": [ 230 | { 231 | "internalType": "uint256", 232 | "name": "", 233 | "type": "uint256" 234 | } 235 | ], 236 | "stateMutability": "view", 237 | "type": "function" 238 | }, 239 | { 240 | "inputs": [ 241 | { 242 | "internalType": "address", 243 | "name": "to", 244 | "type": "address" 245 | }, 246 | { 247 | "internalType": "uint256", 248 | "name": "amount", 249 | "type": "uint256" 250 | } 251 | ], 252 | "name": "transfer", 253 | "outputs": [ 254 | { 255 | "internalType": "bool", 256 | "name": "", 257 | "type": "bool" 258 | } 259 | ], 260 | "stateMutability": "nonpayable", 261 | "type": "function" 262 | }, 263 | { 264 | "inputs": [ 265 | { 266 | "internalType": "address", 267 | "name": "from", 268 | "type": "address" 269 | }, 270 | { 271 | "internalType": "address", 272 | "name": "to", 273 | "type": "address" 274 | }, 275 | { 276 | "internalType": "uint256", 277 | "name": "amount", 278 | "type": "uint256" 279 | } 280 | ], 281 | "name": "transferFrom", 282 | "outputs": [ 283 | { 284 | "internalType": "bool", 285 | "name": "", 286 | "type": "bool" 287 | } 288 | ], 289 | "stateMutability": "nonpayable", 290 | "type": "function" 291 | } 292 | ], 293 | "bytecode": "0x60806040523480156200001157600080fd5b5060405162000b1938038062000b198339810160408190526200003491620001db565b81516200004990600390602085019062000068565b5080516200005f90600490602084019062000068565b50505062000282565b828054620000769062000245565b90600052602060002090601f0160209004810192826200009a5760008555620000e5565b82601f10620000b557805160ff1916838001178555620000e5565b82800160010185558215620000e5579182015b82811115620000e5578251825591602001919060010190620000c8565b50620000f3929150620000f7565b5090565b5b80821115620000f35760008155600101620000f8565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200013657600080fd5b81516001600160401b03808211156200015357620001536200010e565b604051601f8301601f19908116603f011681019082821181831017156200017e576200017e6200010e565b816040528381526020925086838588010111156200019b57600080fd5b600091505b83821015620001bf5785820183015181830184015290820190620001a0565b83821115620001d15760008385830101525b9695505050505050565b60008060408385031215620001ef57600080fd5b82516001600160401b03808211156200020757600080fd5b620002158683870162000124565b935060208501519150808211156200022c57600080fd5b506200023b8582860162000124565b9150509250929050565b600181811c908216806200025a57607f821691505b602082108114156200027c57634e487b7160e01b600052602260045260246000fd5b50919050565b61088780620002926000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461012357806370a082311461013657806395d89b411461015f578063a457c2d714610167578063a9059cbb1461017a578063dd62ed3e1461018d57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101a0565b6040516100c391906106c4565b60405180910390f35b6100df6100da366004610735565b610232565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f36600461075f565b61024a565b604051601281526020016100c3565b6100df610131366004610735565b61026e565b6100f361014436600461079b565b6001600160a01b031660009081526020819052604090205490565b6100b6610290565b6100df610175366004610735565b61029f565b6100df610188366004610735565b61031f565b6100f361019b3660046107bd565b61032d565b6060600380546101af906107f0565b80601f01602080910402602001604051908101604052809291908181526020018280546101db906107f0565b80156102285780601f106101fd57610100808354040283529160200191610228565b820191906000526020600020905b81548152906001019060200180831161020b57829003601f168201915b5050505050905090565b600033610240818585610358565b5060019392505050565b60003361025885828561047c565b6102638585856104f6565b506001949350505050565b600033610240818585610281838361032d565b61028b919061082b565b610358565b6060600480546101af906107f0565b600033816102ad828661032d565b9050838110156103125760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b6102638286868403610358565b6000336102408185856104f6565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103ba5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610309565b6001600160a01b03821661041b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610309565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6000610488848461032d565b905060001981146104f057818110156104e35760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610309565b6104f08484848403610358565b50505050565b6001600160a01b03831661055a5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610309565b6001600160a01b0382166105bc5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610309565b6001600160a01b038316600090815260208190526040902054818110156106345760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610309565b6001600160a01b0380851660009081526020819052604080822085850390559185168152908120805484929061066b90849061082b565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516106b791815260200190565b60405180910390a36104f0565b600060208083528351808285015260005b818110156106f1578581018301518582016040015282016106d5565b81811115610703576000604083870101525b50601f01601f1916929092016040019392505050565b80356001600160a01b038116811461073057600080fd5b919050565b6000806040838503121561074857600080fd5b61075183610719565b946020939093013593505050565b60008060006060848603121561077457600080fd5b61077d84610719565b925061078b60208501610719565b9150604084013590509250925092565b6000602082840312156107ad57600080fd5b6107b682610719565b9392505050565b600080604083850312156107d057600080fd5b6107d983610719565b91506107e760208401610719565b90509250929050565b600181811c9082168061080457607f821691505b6020821081141561082557634e487b7160e01b600052602260045260246000fd5b50919050565b6000821982111561084c57634e487b7160e01b600052601160045260246000fd5b50019056fea264697066735822122042927ef850062b7faaf2c6690cf9d9316daee77b6792d1fba6931fe374706f5064736f6c63430008090033", 294 | "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461012357806370a082311461013657806395d89b411461015f578063a457c2d714610167578063a9059cbb1461017a578063dd62ed3e1461018d57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101a0565b6040516100c391906106c4565b60405180910390f35b6100df6100da366004610735565b610232565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f36600461075f565b61024a565b604051601281526020016100c3565b6100df610131366004610735565b61026e565b6100f361014436600461079b565b6001600160a01b031660009081526020819052604090205490565b6100b6610290565b6100df610175366004610735565b61029f565b6100df610188366004610735565b61031f565b6100f361019b3660046107bd565b61032d565b6060600380546101af906107f0565b80601f01602080910402602001604051908101604052809291908181526020018280546101db906107f0565b80156102285780601f106101fd57610100808354040283529160200191610228565b820191906000526020600020905b81548152906001019060200180831161020b57829003601f168201915b5050505050905090565b600033610240818585610358565b5060019392505050565b60003361025885828561047c565b6102638585856104f6565b506001949350505050565b600033610240818585610281838361032d565b61028b919061082b565b610358565b6060600480546101af906107f0565b600033816102ad828661032d565b9050838110156103125760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b6102638286868403610358565b6000336102408185856104f6565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103ba5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610309565b6001600160a01b03821661041b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610309565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6000610488848461032d565b905060001981146104f057818110156104e35760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610309565b6104f08484848403610358565b50505050565b6001600160a01b03831661055a5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610309565b6001600160a01b0382166105bc5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610309565b6001600160a01b038316600090815260208190526040902054818110156106345760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610309565b6001600160a01b0380851660009081526020819052604080822085850390559185168152908120805484929061066b90849061082b565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516106b791815260200190565b60405180910390a36104f0565b600060208083528351808285015260005b818110156106f1578581018301518582016040015282016106d5565b81811115610703576000604083870101525b50601f01601f1916929092016040019392505050565b80356001600160a01b038116811461073057600080fd5b919050565b6000806040838503121561074857600080fd5b61075183610719565b946020939093013593505050565b60008060006060848603121561077457600080fd5b61077d84610719565b925061078b60208501610719565b9150604084013590509250925092565b6000602082840312156107ad57600080fd5b6107b682610719565b9392505050565b600080604083850312156107d057600080fd5b6107d983610719565b91506107e760208401610719565b90509250929050565b600181811c9082168061080457607f821691505b6020821081141561082557634e487b7160e01b600052602260045260246000fd5b50919050565b6000821982111561084c57634e487b7160e01b600052601160045260246000fd5b50019056fea264697066735822122042927ef850062b7faaf2c6690cf9d9316daee77b6792d1fba6931fe374706f5064736f6c63430008090033", 295 | "linkReferences": {}, 296 | "deployedLinkReferences": {} 297 | } 298 | -------------------------------------------------------------------------------- /ERC721.json: -------------------------------------------------------------------------------- 1 | { 2 | "_format": "hh-sol-artifact-1", 3 | "contractName": "ERC721", 4 | "sourceName": "contracts/token/ERC721/ERC721.sol", 5 | "abi": [ 6 | { 7 | "inputs": [ 8 | { 9 | "internalType": "string", 10 | "name": "name_", 11 | "type": "string" 12 | }, 13 | { 14 | "internalType": "string", 15 | "name": "symbol_", 16 | "type": "string" 17 | } 18 | ], 19 | "stateMutability": "nonpayable", 20 | "type": "constructor" 21 | }, 22 | { 23 | "anonymous": false, 24 | "inputs": [ 25 | { 26 | "indexed": true, 27 | "internalType": "address", 28 | "name": "owner", 29 | "type": "address" 30 | }, 31 | { 32 | "indexed": true, 33 | "internalType": "address", 34 | "name": "approved", 35 | "type": "address" 36 | }, 37 | { 38 | "indexed": true, 39 | "internalType": "uint256", 40 | "name": "tokenId", 41 | "type": "uint256" 42 | } 43 | ], 44 | "name": "Approval", 45 | "type": "event" 46 | }, 47 | { 48 | "anonymous": false, 49 | "inputs": [ 50 | { 51 | "indexed": true, 52 | "internalType": "address", 53 | "name": "owner", 54 | "type": "address" 55 | }, 56 | { 57 | "indexed": true, 58 | "internalType": "address", 59 | "name": "operator", 60 | "type": "address" 61 | }, 62 | { 63 | "indexed": false, 64 | "internalType": "bool", 65 | "name": "approved", 66 | "type": "bool" 67 | } 68 | ], 69 | "name": "ApprovalForAll", 70 | "type": "event" 71 | }, 72 | { 73 | "anonymous": false, 74 | "inputs": [ 75 | { 76 | "indexed": true, 77 | "internalType": "address", 78 | "name": "from", 79 | "type": "address" 80 | }, 81 | { 82 | "indexed": true, 83 | "internalType": "address", 84 | "name": "to", 85 | "type": "address" 86 | }, 87 | { 88 | "indexed": true, 89 | "internalType": "uint256", 90 | "name": "tokenId", 91 | "type": "uint256" 92 | } 93 | ], 94 | "name": "Transfer", 95 | "type": "event" 96 | }, 97 | { 98 | "inputs": [ 99 | { 100 | "internalType": "address", 101 | "name": "to", 102 | "type": "address" 103 | }, 104 | { 105 | "internalType": "uint256", 106 | "name": "tokenId", 107 | "type": "uint256" 108 | } 109 | ], 110 | "name": "approve", 111 | "outputs": [], 112 | "stateMutability": "nonpayable", 113 | "type": "function" 114 | }, 115 | { 116 | "inputs": [ 117 | { 118 | "internalType": "address", 119 | "name": "owner", 120 | "type": "address" 121 | } 122 | ], 123 | "name": "balanceOf", 124 | "outputs": [ 125 | { 126 | "internalType": "uint256", 127 | "name": "", 128 | "type": "uint256" 129 | } 130 | ], 131 | "stateMutability": "view", 132 | "type": "function" 133 | }, 134 | { 135 | "inputs": [ 136 | { 137 | "internalType": "uint256", 138 | "name": "tokenId", 139 | "type": "uint256" 140 | } 141 | ], 142 | "name": "getApproved", 143 | "outputs": [ 144 | { 145 | "internalType": "address", 146 | "name": "", 147 | "type": "address" 148 | } 149 | ], 150 | "stateMutability": "view", 151 | "type": "function" 152 | }, 153 | { 154 | "inputs": [ 155 | { 156 | "internalType": "address", 157 | "name": "owner", 158 | "type": "address" 159 | }, 160 | { 161 | "internalType": "address", 162 | "name": "operator", 163 | "type": "address" 164 | } 165 | ], 166 | "name": "isApprovedForAll", 167 | "outputs": [ 168 | { 169 | "internalType": "bool", 170 | "name": "", 171 | "type": "bool" 172 | } 173 | ], 174 | "stateMutability": "view", 175 | "type": "function" 176 | }, 177 | { 178 | "inputs": [], 179 | "name": "name", 180 | "outputs": [ 181 | { 182 | "internalType": "string", 183 | "name": "", 184 | "type": "string" 185 | } 186 | ], 187 | "stateMutability": "view", 188 | "type": "function" 189 | }, 190 | { 191 | "inputs": [ 192 | { 193 | "internalType": "uint256", 194 | "name": "tokenId", 195 | "type": "uint256" 196 | } 197 | ], 198 | "name": "ownerOf", 199 | "outputs": [ 200 | { 201 | "internalType": "address", 202 | "name": "", 203 | "type": "address" 204 | } 205 | ], 206 | "stateMutability": "view", 207 | "type": "function" 208 | }, 209 | { 210 | "inputs": [ 211 | { 212 | "internalType": "address", 213 | "name": "from", 214 | "type": "address" 215 | }, 216 | { 217 | "internalType": "address", 218 | "name": "to", 219 | "type": "address" 220 | }, 221 | { 222 | "internalType": "uint256", 223 | "name": "tokenId", 224 | "type": "uint256" 225 | } 226 | ], 227 | "name": "safeTransferFrom", 228 | "outputs": [], 229 | "stateMutability": "nonpayable", 230 | "type": "function" 231 | }, 232 | { 233 | "inputs": [ 234 | { 235 | "internalType": "address", 236 | "name": "from", 237 | "type": "address" 238 | }, 239 | { 240 | "internalType": "address", 241 | "name": "to", 242 | "type": "address" 243 | }, 244 | { 245 | "internalType": "uint256", 246 | "name": "tokenId", 247 | "type": "uint256" 248 | }, 249 | { 250 | "internalType": "bytes", 251 | "name": "_data", 252 | "type": "bytes" 253 | } 254 | ], 255 | "name": "safeTransferFrom", 256 | "outputs": [], 257 | "stateMutability": "nonpayable", 258 | "type": "function" 259 | }, 260 | { 261 | "inputs": [ 262 | { 263 | "internalType": "address", 264 | "name": "operator", 265 | "type": "address" 266 | }, 267 | { 268 | "internalType": "bool", 269 | "name": "approved", 270 | "type": "bool" 271 | } 272 | ], 273 | "name": "setApprovalForAll", 274 | "outputs": [], 275 | "stateMutability": "nonpayable", 276 | "type": "function" 277 | }, 278 | { 279 | "inputs": [ 280 | { 281 | "internalType": "bytes4", 282 | "name": "interfaceId", 283 | "type": "bytes4" 284 | } 285 | ], 286 | "name": "supportsInterface", 287 | "outputs": [ 288 | { 289 | "internalType": "bool", 290 | "name": "", 291 | "type": "bool" 292 | } 293 | ], 294 | "stateMutability": "view", 295 | "type": "function" 296 | }, 297 | { 298 | "inputs": [], 299 | "name": "symbol", 300 | "outputs": [ 301 | { 302 | "internalType": "string", 303 | "name": "", 304 | "type": "string" 305 | } 306 | ], 307 | "stateMutability": "view", 308 | "type": "function" 309 | }, 310 | { 311 | "inputs": [ 312 | { 313 | "internalType": "uint256", 314 | "name": "tokenId", 315 | "type": "uint256" 316 | } 317 | ], 318 | "name": "tokenURI", 319 | "outputs": [ 320 | { 321 | "internalType": "string", 322 | "name": "", 323 | "type": "string" 324 | } 325 | ], 326 | "stateMutability": "view", 327 | "type": "function" 328 | }, 329 | { 330 | "inputs": [ 331 | { 332 | "internalType": "address", 333 | "name": "from", 334 | "type": "address" 335 | }, 336 | { 337 | "internalType": "address", 338 | "name": "to", 339 | "type": "address" 340 | }, 341 | { 342 | "internalType": "uint256", 343 | "name": "tokenId", 344 | "type": "uint256" 345 | } 346 | ], 347 | "name": "transferFrom", 348 | "outputs": [], 349 | "stateMutability": "nonpayable", 350 | "type": "function" 351 | } 352 | ], 353 | "bytecode": "0x60806040523480156200001157600080fd5b50604051620014ec380380620014ec8339810160408190526200003491620001db565b81516200004990600090602085019062000068565b5080516200005f90600190602084019062000068565b50505062000282565b828054620000769062000245565b90600052602060002090601f0160209004810192826200009a5760008555620000e5565b82601f10620000b557805160ff1916838001178555620000e5565b82800160010185558215620000e5579182015b82811115620000e5578251825591602001919060010190620000c8565b50620000f3929150620000f7565b5090565b5b80821115620000f35760008155600101620000f8565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200013657600080fd5b81516001600160401b03808211156200015357620001536200010e565b604051601f8301601f19908116603f011681019082821181831017156200017e576200017e6200010e565b816040528381526020925086838588010111156200019b57600080fd5b600091505b83821015620001bf5785820183015181830184015290820190620001a0565b83821115620001d15760008385830101525b9695505050505050565b60008060408385031215620001ef57600080fd5b82516001600160401b03808211156200020757600080fd5b620002158683870162000124565b935060208501519150808211156200022c57600080fd5b506200023b8582860162000124565b9150509250929050565b600181811c908216806200025a57607f821691505b602082108114156200027c57634e487b7160e01b600052602260045260246000fd5b50919050565b61125a80620002926000396000f3fe608060405234801561001057600080fd5b50600436106100cf5760003560e01c80636352211e1161008c578063a22cb46511610066578063a22cb465146101b3578063b88d4fde146101c6578063c87b56dd146101d9578063e985e9c5146101ec57600080fd5b80636352211e1461017757806370a082311461018a57806395d89b41146101ab57600080fd5b806301ffc9a7146100d457806306fdde03146100fc578063081812fc14610111578063095ea7b31461013c57806323b872dd1461015157806342842e0e14610164575b600080fd5b6100e76100e2366004610d6a565b610228565b60405190151581526020015b60405180910390f35b61010461027a565b6040516100f39190610ddf565b61012461011f366004610df2565b61030c565b6040516001600160a01b0390911681526020016100f3565b61014f61014a366004610e27565b6103a6565b005b61014f61015f366004610e51565b6104bc565b61014f610172366004610e51565b6104ed565b610124610185366004610df2565b610508565b61019d610198366004610e8d565b61057f565b6040519081526020016100f3565b610104610605565b61014f6101c1366004610ea8565b610614565b61014f6101d4366004610efa565b610623565b6101046101e7366004610df2565b61065b565b6100e76101fa366004610fd6565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b60006001600160e01b031982166380ac58cd60e01b148061025957506001600160e01b03198216635b5e139f60e01b145b8061027457506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606000805461028990611009565b80601f01602080910402602001604051908101604052809291908181526020018280546102b590611009565b80156103025780601f106102d757610100808354040283529160200191610302565b820191906000526020600020905b8154815290600101906020018083116102e557829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661038a5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60006103b182610508565b9050806001600160a01b0316836001600160a01b0316141561041f5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610381565b336001600160a01b038216148061043b575061043b81336101fa565b6104ad5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610381565b6104b78383610743565b505050565b6104c633826107b1565b6104e25760405162461bcd60e51b815260040161038190611044565b6104b78383836108a8565b6104b783838360405180602001604052806000815250610623565b6000818152600260205260408120546001600160a01b0316806102745760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610381565b60006001600160a01b0382166105e95760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610381565b506001600160a01b031660009081526003602052604090205490565b60606001805461028990611009565b61061f338383610a44565b5050565b61062d33836107b1565b6106495760405162461bcd60e51b815260040161038190611044565b61065584848484610b13565b50505050565b6000818152600260205260409020546060906001600160a01b03166106da5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610381565b60006106f160408051602081019091526000815290565b90506000815111610711576040518060200160405280600081525061073c565b8061071b84610b46565b60405160200161072c929190611095565b6040516020818303038152906040525b9392505050565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061077882610508565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b031661082a5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610381565b600061083583610508565b9050806001600160a01b0316846001600160a01b0316148061087c57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b806108a05750836001600160a01b03166108958461030c565b6001600160a01b0316145b949350505050565b826001600160a01b03166108bb82610508565b6001600160a01b03161461091f5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610381565b6001600160a01b0382166109815760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610381565b61098c600082610743565b6001600160a01b03831660009081526003602052604081208054600192906109b59084906110da565b90915550506001600160a01b03821660009081526003602052604081208054600192906109e39084906110f1565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b816001600160a01b0316836001600160a01b03161415610aa65760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610381565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b610b1e8484846108a8565b610b2a84848484610c44565b6106555760405162461bcd60e51b815260040161038190611109565b606081610b6a5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115610b945780610b7e8161115b565b9150610b8d9050600a8361118c565b9150610b6e565b60008167ffffffffffffffff811115610baf57610baf610ee4565b6040519080825280601f01601f191660200182016040528015610bd9576020820181803683370190505b5090505b84156108a057610bee6001836110da565b9150610bfb600a866111a0565b610c069060306110f1565b60f81b818381518110610c1b57610c1b6111b4565b60200101906001600160f81b031916908160001a905350610c3d600a8661118c565b9450610bdd565b60006001600160a01b0384163b15610d4657604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290610c889033908990889088906004016111ca565b602060405180830381600087803b158015610ca257600080fd5b505af1925050508015610cd2575060408051601f3d908101601f19168201909252610ccf91810190611207565b60015b610d2c573d808015610d00576040519150601f19603f3d011682016040523d82523d6000602084013e610d05565b606091505b508051610d245760405162461bcd60e51b815260040161038190611109565b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490506108a0565b506001949350505050565b6001600160e01b031981168114610d6757600080fd5b50565b600060208284031215610d7c57600080fd5b813561073c81610d51565b60005b83811015610da2578181015183820152602001610d8a565b838111156106555750506000910152565b60008151808452610dcb816020860160208601610d87565b601f01601f19169290920160200192915050565b60208152600061073c6020830184610db3565b600060208284031215610e0457600080fd5b5035919050565b80356001600160a01b0381168114610e2257600080fd5b919050565b60008060408385031215610e3a57600080fd5b610e4383610e0b565b946020939093013593505050565b600080600060608486031215610e6657600080fd5b610e6f84610e0b565b9250610e7d60208501610e0b565b9150604084013590509250925092565b600060208284031215610e9f57600080fd5b61073c82610e0b565b60008060408385031215610ebb57600080fd5b610ec483610e0b565b915060208301358015158114610ed957600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b60008060008060808587031215610f1057600080fd5b610f1985610e0b565b9350610f2760208601610e0b565b925060408501359150606085013567ffffffffffffffff80821115610f4b57600080fd5b818701915087601f830112610f5f57600080fd5b813581811115610f7157610f71610ee4565b604051601f8201601f19908116603f01168101908382118183101715610f9957610f99610ee4565b816040528281528a6020848701011115610fb257600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215610fe957600080fd5b610ff283610e0b565b915061100060208401610e0b565b90509250929050565b600181811c9082168061101d57607f821691505b6020821081141561103e57634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b600083516110a7818460208801610d87565b8351908301906110bb818360208801610d87565b01949350505050565b634e487b7160e01b600052601160045260246000fd5b6000828210156110ec576110ec6110c4565b500390565b60008219821115611104576111046110c4565b500190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b600060001982141561116f5761116f6110c4565b5060010190565b634e487b7160e01b600052601260045260246000fd5b60008261119b5761119b611176565b500490565b6000826111af576111af611176565b500690565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906111fd90830184610db3565b9695505050505050565b60006020828403121561121957600080fd5b815161073c81610d5156fea264697066735822122057e062e7b2248f893c71cfb27d800c371342ffa96f43226713fb4743bbf483ab64736f6c63430008090033", 354 | "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c80636352211e1161008c578063a22cb46511610066578063a22cb465146101b3578063b88d4fde146101c6578063c87b56dd146101d9578063e985e9c5146101ec57600080fd5b80636352211e1461017757806370a082311461018a57806395d89b41146101ab57600080fd5b806301ffc9a7146100d457806306fdde03146100fc578063081812fc14610111578063095ea7b31461013c57806323b872dd1461015157806342842e0e14610164575b600080fd5b6100e76100e2366004610d6a565b610228565b60405190151581526020015b60405180910390f35b61010461027a565b6040516100f39190610ddf565b61012461011f366004610df2565b61030c565b6040516001600160a01b0390911681526020016100f3565b61014f61014a366004610e27565b6103a6565b005b61014f61015f366004610e51565b6104bc565b61014f610172366004610e51565b6104ed565b610124610185366004610df2565b610508565b61019d610198366004610e8d565b61057f565b6040519081526020016100f3565b610104610605565b61014f6101c1366004610ea8565b610614565b61014f6101d4366004610efa565b610623565b6101046101e7366004610df2565b61065b565b6100e76101fa366004610fd6565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b60006001600160e01b031982166380ac58cd60e01b148061025957506001600160e01b03198216635b5e139f60e01b145b8061027457506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606000805461028990611009565b80601f01602080910402602001604051908101604052809291908181526020018280546102b590611009565b80156103025780601f106102d757610100808354040283529160200191610302565b820191906000526020600020905b8154815290600101906020018083116102e557829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661038a5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60006103b182610508565b9050806001600160a01b0316836001600160a01b0316141561041f5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610381565b336001600160a01b038216148061043b575061043b81336101fa565b6104ad5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610381565b6104b78383610743565b505050565b6104c633826107b1565b6104e25760405162461bcd60e51b815260040161038190611044565b6104b78383836108a8565b6104b783838360405180602001604052806000815250610623565b6000818152600260205260408120546001600160a01b0316806102745760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610381565b60006001600160a01b0382166105e95760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610381565b506001600160a01b031660009081526003602052604090205490565b60606001805461028990611009565b61061f338383610a44565b5050565b61062d33836107b1565b6106495760405162461bcd60e51b815260040161038190611044565b61065584848484610b13565b50505050565b6000818152600260205260409020546060906001600160a01b03166106da5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610381565b60006106f160408051602081019091526000815290565b90506000815111610711576040518060200160405280600081525061073c565b8061071b84610b46565b60405160200161072c929190611095565b6040516020818303038152906040525b9392505050565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061077882610508565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b031661082a5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610381565b600061083583610508565b9050806001600160a01b0316846001600160a01b0316148061087c57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b806108a05750836001600160a01b03166108958461030c565b6001600160a01b0316145b949350505050565b826001600160a01b03166108bb82610508565b6001600160a01b03161461091f5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610381565b6001600160a01b0382166109815760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610381565b61098c600082610743565b6001600160a01b03831660009081526003602052604081208054600192906109b59084906110da565b90915550506001600160a01b03821660009081526003602052604081208054600192906109e39084906110f1565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b816001600160a01b0316836001600160a01b03161415610aa65760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610381565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b610b1e8484846108a8565b610b2a84848484610c44565b6106555760405162461bcd60e51b815260040161038190611109565b606081610b6a5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115610b945780610b7e8161115b565b9150610b8d9050600a8361118c565b9150610b6e565b60008167ffffffffffffffff811115610baf57610baf610ee4565b6040519080825280601f01601f191660200182016040528015610bd9576020820181803683370190505b5090505b84156108a057610bee6001836110da565b9150610bfb600a866111a0565b610c069060306110f1565b60f81b818381518110610c1b57610c1b6111b4565b60200101906001600160f81b031916908160001a905350610c3d600a8661118c565b9450610bdd565b60006001600160a01b0384163b15610d4657604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290610c889033908990889088906004016111ca565b602060405180830381600087803b158015610ca257600080fd5b505af1925050508015610cd2575060408051601f3d908101601f19168201909252610ccf91810190611207565b60015b610d2c573d808015610d00576040519150601f19603f3d011682016040523d82523d6000602084013e610d05565b606091505b508051610d245760405162461bcd60e51b815260040161038190611109565b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490506108a0565b506001949350505050565b6001600160e01b031981168114610d6757600080fd5b50565b600060208284031215610d7c57600080fd5b813561073c81610d51565b60005b83811015610da2578181015183820152602001610d8a565b838111156106555750506000910152565b60008151808452610dcb816020860160208601610d87565b601f01601f19169290920160200192915050565b60208152600061073c6020830184610db3565b600060208284031215610e0457600080fd5b5035919050565b80356001600160a01b0381168114610e2257600080fd5b919050565b60008060408385031215610e3a57600080fd5b610e4383610e0b565b946020939093013593505050565b600080600060608486031215610e6657600080fd5b610e6f84610e0b565b9250610e7d60208501610e0b565b9150604084013590509250925092565b600060208284031215610e9f57600080fd5b61073c82610e0b565b60008060408385031215610ebb57600080fd5b610ec483610e0b565b915060208301358015158114610ed957600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b60008060008060808587031215610f1057600080fd5b610f1985610e0b565b9350610f2760208601610e0b565b925060408501359150606085013567ffffffffffffffff80821115610f4b57600080fd5b818701915087601f830112610f5f57600080fd5b813581811115610f7157610f71610ee4565b604051601f8201601f19908116603f01168101908382118183101715610f9957610f99610ee4565b816040528281528a6020848701011115610fb257600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215610fe957600080fd5b610ff283610e0b565b915061100060208401610e0b565b90509250929050565b600181811c9082168061101d57607f821691505b6020821081141561103e57634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b600083516110a7818460208801610d87565b8351908301906110bb818360208801610d87565b01949350505050565b634e487b7160e01b600052601160045260246000fd5b6000828210156110ec576110ec6110c4565b500390565b60008219821115611104576111046110c4565b500190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b600060001982141561116f5761116f6110c4565b5060010190565b634e487b7160e01b600052601260045260246000fd5b60008261119b5761119b611176565b500490565b6000826111af576111af611176565b500690565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906111fd90830184610db3565b9695505050505050565b60006020828403121561121957600080fd5b815161073c81610d5156fea264697066735822122057e062e7b2248f893c71cfb27d800c371342ffa96f43226713fb4743bbf483ab64736f6c63430008090033", 355 | "linkReferences": {}, 356 | "deployedLinkReferences": {} 357 | } 358 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | This repository contains multiple files that can interact with EVM based blockchain with web3.php 3 | 4 | ## Usage 5 | * Clone and install package 6 | 7 | ``` 8 | $ git clone https://github.com/web3p/examples.git && cd examples && composer install 9 | ``` 10 | 11 | * Update exampleBase.php / ERC20.json / ERC721.json 12 | 13 | Next, you can update these files (exampleBase.php / ERC20.json / ERC721.json), and have fun. 14 | 15 | ## Files 16 | 17 | * erc20.php 18 | 19 | Deploy erc20 token and tranfer tokens. 20 | 21 | * nft.php 22 | 23 | Deploy erc721 token and mint token. 24 | 25 | * swap.php 26 | 27 | Swap a token to b token on UniswapV2 based DEX, remember to find the right router and path. 28 | 29 | * tx.php 30 | 31 | Transfer eth / bsc to the other account. 32 | 33 | * exampleBase.php / utils.php 34 | 35 | Basic files for these examples. 36 | 37 | Special thanks to https://twitter.com/aube_patrick for support this project. -------------------------------------------------------------------------------- /UNIV2Router.json: -------------------------------------------------------------------------------- 1 | { 2 | "_format": "hh-sol-artifact-1", 3 | "contractName": "UNIV2Router", 4 | "sourceName": "contracts/web3p/UNIV2Router.sol", 5 | "abi": [ 6 | { 7 | "inputs":[ 8 | {"internalType":"uint256","name":"amountOutMin","type":"uint256"}, 9 | {"internalType":"address[]","name":"path","type":"address[]"}, 10 | {"internalType":"address","name":"to","type":"address"}, 11 | {"internalType":"uint256","name":"deadline","type":"uint256"} 12 | ], 13 | "name":"swapExactETHForTokens", 14 | "outputs":[ 15 | {"internalType":"uint256[]","name":"amounts","type":"uint256[]"} 16 | ], 17 | "stateMutability":"payable", 18 | "type":"function" 19 | }, 20 | { 21 | "inputs":[ 22 | {"internalType":"uint256","name":"amountIn","type":"uint256"}, 23 | {"internalType":"uint256","name":"amountOutMin","type":"uint256"}, 24 | {"internalType":"address[]","name":"path","type":"address[]"}, 25 | {"internalType":"address","name":"to","type":"address"}, 26 | {"internalType":"uint256","name":"deadline","type":"uint256"} 27 | ], 28 | "name":"swapExactTokensForTokens", 29 | "outputs":[ 30 | {"internalType":"uint256[]","name":"amounts","type":"uint256[]"} 31 | ], 32 | "stateMutability":"nonpayable", 33 | "type":"function" 34 | }, 35 | { 36 | "inputs":[ 37 | {"internalType":"uint256","name":"amountIn","type":"uint256"}, 38 | {"internalType":"uint256","name":"amountOutMin","type":"uint256"}, 39 | {"internalType":"address[]","name":"path","type":"address[]"}, 40 | {"internalType":"address","name":"to","type":"address"}, 41 | {"internalType":"uint256","name":"deadline","type":"uint256"} 42 | ], 43 | "name":"swapExactTokensForETH", 44 | "outputs":[ 45 | {"internalType":"uint256[]","name":"amounts","type":"uint256[]"} 46 | ], 47 | "stateMutability":"nonpayable", 48 | "type":"function" 49 | }, 50 | { 51 | "inputs":[ 52 | {"internalType":"uint256","name":"amountIn","type":"uint256"}, 53 | {"internalType":"address[]","name":"path","type":"address[]"} 54 | ], 55 | "name":"getAmountsOut", 56 | "outputs":[ 57 | {"internalType":"uint256[]","name":"amounts","type":"uint256[]"} 58 | ], 59 | "stateMutability":"nonpayable", 60 | "type":"function" 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web3p/examples", 3 | "description": "Patrick test project.", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "sc0Vu", 9 | "email": "alk03073135@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "guzzlehttp/guzzle": "^6.3 | ^7.0", 14 | "PHP": "^7.1|^8.0", 15 | "kornrunner/keccak": "~1.0", 16 | "phpseclib/phpseclib": "~2.0.11", 17 | "ext-mbstring": "*", 18 | "web3p/ethereum-tx": "^0.4.3", 19 | "web3p/web3.php": "^0.1.5" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "c53e966aff21205931e131dd1cdc9b58", 8 | "packages": [ 9 | { 10 | "name": "guzzlehttp/guzzle", 11 | "version": "7.4.2", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/guzzle/guzzle.git", 15 | "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ac1ec1cd9b5624694c3a40be801d94137afb12b4", 20 | "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "ext-json": "*", 25 | "guzzlehttp/promises": "^1.5", 26 | "guzzlehttp/psr7": "^1.8.3 || ^2.1", 27 | "php": "^7.2.5 || ^8.0", 28 | "psr/http-client": "^1.0", 29 | "symfony/deprecation-contracts": "^2.2 || ^3.0" 30 | }, 31 | "provide": { 32 | "psr/http-client-implementation": "1.0" 33 | }, 34 | "require-dev": { 35 | "bamarni/composer-bin-plugin": "^1.4.1", 36 | "ext-curl": "*", 37 | "php-http/client-integration-tests": "^3.0", 38 | "phpunit/phpunit": "^8.5.5 || ^9.3.5", 39 | "psr/log": "^1.1 || ^2.0 || ^3.0" 40 | }, 41 | "suggest": { 42 | "ext-curl": "Required for CURL handler support", 43 | "ext-intl": "Required for Internationalized Domain Name (IDN) support", 44 | "psr/log": "Required for using the Log middleware" 45 | }, 46 | "type": "library", 47 | "extra": { 48 | "branch-alias": { 49 | "dev-master": "7.4-dev" 50 | } 51 | }, 52 | "autoload": { 53 | "files": [ 54 | "src/functions_include.php" 55 | ], 56 | "psr-4": { 57 | "GuzzleHttp\\": "src/" 58 | } 59 | }, 60 | "notification-url": "https://packagist.org/downloads/", 61 | "license": [ 62 | "MIT" 63 | ], 64 | "authors": [ 65 | { 66 | "name": "Graham Campbell", 67 | "email": "hello@gjcampbell.co.uk", 68 | "homepage": "https://github.com/GrahamCampbell" 69 | }, 70 | { 71 | "name": "Michael Dowling", 72 | "email": "mtdowling@gmail.com", 73 | "homepage": "https://github.com/mtdowling" 74 | }, 75 | { 76 | "name": "Jeremy Lindblom", 77 | "email": "jeremeamia@gmail.com", 78 | "homepage": "https://github.com/jeremeamia" 79 | }, 80 | { 81 | "name": "George Mponos", 82 | "email": "gmponos@gmail.com", 83 | "homepage": "https://github.com/gmponos" 84 | }, 85 | { 86 | "name": "Tobias Nyholm", 87 | "email": "tobias.nyholm@gmail.com", 88 | "homepage": "https://github.com/Nyholm" 89 | }, 90 | { 91 | "name": "Márk Sági-Kazár", 92 | "email": "mark.sagikazar@gmail.com", 93 | "homepage": "https://github.com/sagikazarmark" 94 | }, 95 | { 96 | "name": "Tobias Schultze", 97 | "email": "webmaster@tubo-world.de", 98 | "homepage": "https://github.com/Tobion" 99 | } 100 | ], 101 | "description": "Guzzle is a PHP HTTP client library", 102 | "keywords": [ 103 | "client", 104 | "curl", 105 | "framework", 106 | "http", 107 | "http client", 108 | "psr-18", 109 | "psr-7", 110 | "rest", 111 | "web service" 112 | ], 113 | "support": { 114 | "issues": "https://github.com/guzzle/guzzle/issues", 115 | "source": "https://github.com/guzzle/guzzle/tree/7.4.2" 116 | }, 117 | "funding": [ 118 | { 119 | "url": "https://github.com/GrahamCampbell", 120 | "type": "github" 121 | }, 122 | { 123 | "url": "https://github.com/Nyholm", 124 | "type": "github" 125 | }, 126 | { 127 | "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", 128 | "type": "tidelift" 129 | } 130 | ], 131 | "time": "2022-03-20T14:16:28+00:00" 132 | }, 133 | { 134 | "name": "guzzlehttp/promises", 135 | "version": "1.5.1", 136 | "source": { 137 | "type": "git", 138 | "url": "https://github.com/guzzle/promises.git", 139 | "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da" 140 | }, 141 | "dist": { 142 | "type": "zip", 143 | "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da", 144 | "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da", 145 | "shasum": "" 146 | }, 147 | "require": { 148 | "php": ">=5.5" 149 | }, 150 | "require-dev": { 151 | "symfony/phpunit-bridge": "^4.4 || ^5.1" 152 | }, 153 | "type": "library", 154 | "extra": { 155 | "branch-alias": { 156 | "dev-master": "1.5-dev" 157 | } 158 | }, 159 | "autoload": { 160 | "files": [ 161 | "src/functions_include.php" 162 | ], 163 | "psr-4": { 164 | "GuzzleHttp\\Promise\\": "src/" 165 | } 166 | }, 167 | "notification-url": "https://packagist.org/downloads/", 168 | "license": [ 169 | "MIT" 170 | ], 171 | "authors": [ 172 | { 173 | "name": "Graham Campbell", 174 | "email": "hello@gjcampbell.co.uk", 175 | "homepage": "https://github.com/GrahamCampbell" 176 | }, 177 | { 178 | "name": "Michael Dowling", 179 | "email": "mtdowling@gmail.com", 180 | "homepage": "https://github.com/mtdowling" 181 | }, 182 | { 183 | "name": "Tobias Nyholm", 184 | "email": "tobias.nyholm@gmail.com", 185 | "homepage": "https://github.com/Nyholm" 186 | }, 187 | { 188 | "name": "Tobias Schultze", 189 | "email": "webmaster@tubo-world.de", 190 | "homepage": "https://github.com/Tobion" 191 | } 192 | ], 193 | "description": "Guzzle promises library", 194 | "keywords": [ 195 | "promise" 196 | ], 197 | "support": { 198 | "issues": "https://github.com/guzzle/promises/issues", 199 | "source": "https://github.com/guzzle/promises/tree/1.5.1" 200 | }, 201 | "funding": [ 202 | { 203 | "url": "https://github.com/GrahamCampbell", 204 | "type": "github" 205 | }, 206 | { 207 | "url": "https://github.com/Nyholm", 208 | "type": "github" 209 | }, 210 | { 211 | "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", 212 | "type": "tidelift" 213 | } 214 | ], 215 | "time": "2021-10-22T20:56:57+00:00" 216 | }, 217 | { 218 | "name": "guzzlehttp/psr7", 219 | "version": "2.2.1", 220 | "source": { 221 | "type": "git", 222 | "url": "https://github.com/guzzle/psr7.git", 223 | "reference": "c94a94f120803a18554c1805ef2e539f8285f9a2" 224 | }, 225 | "dist": { 226 | "type": "zip", 227 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/c94a94f120803a18554c1805ef2e539f8285f9a2", 228 | "reference": "c94a94f120803a18554c1805ef2e539f8285f9a2", 229 | "shasum": "" 230 | }, 231 | "require": { 232 | "php": "^7.2.5 || ^8.0", 233 | "psr/http-factory": "^1.0", 234 | "psr/http-message": "^1.0", 235 | "ralouphie/getallheaders": "^3.0" 236 | }, 237 | "provide": { 238 | "psr/http-factory-implementation": "1.0", 239 | "psr/http-message-implementation": "1.0" 240 | }, 241 | "require-dev": { 242 | "bamarni/composer-bin-plugin": "^1.4.1", 243 | "http-interop/http-factory-tests": "^0.9", 244 | "phpunit/phpunit": "^8.5.8 || ^9.3.10" 245 | }, 246 | "suggest": { 247 | "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" 248 | }, 249 | "type": "library", 250 | "extra": { 251 | "branch-alias": { 252 | "dev-master": "2.2-dev" 253 | } 254 | }, 255 | "autoload": { 256 | "psr-4": { 257 | "GuzzleHttp\\Psr7\\": "src/" 258 | } 259 | }, 260 | "notification-url": "https://packagist.org/downloads/", 261 | "license": [ 262 | "MIT" 263 | ], 264 | "authors": [ 265 | { 266 | "name": "Graham Campbell", 267 | "email": "hello@gjcampbell.co.uk", 268 | "homepage": "https://github.com/GrahamCampbell" 269 | }, 270 | { 271 | "name": "Michael Dowling", 272 | "email": "mtdowling@gmail.com", 273 | "homepage": "https://github.com/mtdowling" 274 | }, 275 | { 276 | "name": "George Mponos", 277 | "email": "gmponos@gmail.com", 278 | "homepage": "https://github.com/gmponos" 279 | }, 280 | { 281 | "name": "Tobias Nyholm", 282 | "email": "tobias.nyholm@gmail.com", 283 | "homepage": "https://github.com/Nyholm" 284 | }, 285 | { 286 | "name": "Márk Sági-Kazár", 287 | "email": "mark.sagikazar@gmail.com", 288 | "homepage": "https://github.com/sagikazarmark" 289 | }, 290 | { 291 | "name": "Tobias Schultze", 292 | "email": "webmaster@tubo-world.de", 293 | "homepage": "https://github.com/Tobion" 294 | }, 295 | { 296 | "name": "Márk Sági-Kazár", 297 | "email": "mark.sagikazar@gmail.com", 298 | "homepage": "https://sagikazarmark.hu" 299 | } 300 | ], 301 | "description": "PSR-7 message implementation that also provides common utility methods", 302 | "keywords": [ 303 | "http", 304 | "message", 305 | "psr-7", 306 | "request", 307 | "response", 308 | "stream", 309 | "uri", 310 | "url" 311 | ], 312 | "support": { 313 | "issues": "https://github.com/guzzle/psr7/issues", 314 | "source": "https://github.com/guzzle/psr7/tree/2.2.1" 315 | }, 316 | "funding": [ 317 | { 318 | "url": "https://github.com/GrahamCampbell", 319 | "type": "github" 320 | }, 321 | { 322 | "url": "https://github.com/Nyholm", 323 | "type": "github" 324 | }, 325 | { 326 | "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", 327 | "type": "tidelift" 328 | } 329 | ], 330 | "time": "2022-03-20T21:55:58+00:00" 331 | }, 332 | { 333 | "name": "kornrunner/keccak", 334 | "version": "1.1.0", 335 | "source": { 336 | "type": "git", 337 | "url": "https://github.com/kornrunner/php-keccak.git", 338 | "reference": "433749d28e117fb97baf9f2631b92b5d9ab3c890" 339 | }, 340 | "dist": { 341 | "type": "zip", 342 | "url": "https://api.github.com/repos/kornrunner/php-keccak/zipball/433749d28e117fb97baf9f2631b92b5d9ab3c890", 343 | "reference": "433749d28e117fb97baf9f2631b92b5d9ab3c890", 344 | "shasum": "" 345 | }, 346 | "require": { 347 | "php": ">=7.3", 348 | "symfony/polyfill-mbstring": "^1.8" 349 | }, 350 | "require-dev": { 351 | "phpunit/phpunit": "^8.2" 352 | }, 353 | "type": "library", 354 | "autoload": { 355 | "psr-4": { 356 | "kornrunner\\": "src" 357 | } 358 | }, 359 | "notification-url": "https://packagist.org/downloads/", 360 | "license": [ 361 | "MIT" 362 | ], 363 | "authors": [ 364 | { 365 | "name": "Boris Momcilovic", 366 | "homepage": "https://github.com/kornrunner/php-keccak" 367 | } 368 | ], 369 | "description": "Pure PHP implementation of Keccak", 370 | "keywords": [ 371 | "keccak", 372 | "sha-3", 373 | "sha3-256" 374 | ], 375 | "support": { 376 | "issues": "https://github.com/kornrunner/php-keccak/issues", 377 | "source": "https://github.com/kornrunner/php-keccak/tree/1.1.0" 378 | }, 379 | "time": "2020-12-07T15:40:44+00:00" 380 | }, 381 | { 382 | "name": "phpseclib/phpseclib", 383 | "version": "2.0.37", 384 | "source": { 385 | "type": "git", 386 | "url": "https://github.com/phpseclib/phpseclib.git", 387 | "reference": "c812fbb4d6b4d7f30235ab7298a12f09ba13b37c" 388 | }, 389 | "dist": { 390 | "type": "zip", 391 | "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/c812fbb4d6b4d7f30235ab7298a12f09ba13b37c", 392 | "reference": "c812fbb4d6b4d7f30235ab7298a12f09ba13b37c", 393 | "shasum": "" 394 | }, 395 | "require": { 396 | "php": ">=5.3.3" 397 | }, 398 | "require-dev": { 399 | "phing/phing": "~2.7", 400 | "phpunit/phpunit": "^4.8.35|^5.7|^6.0|^9.4", 401 | "squizlabs/php_codesniffer": "~2.0" 402 | }, 403 | "suggest": { 404 | "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.", 405 | "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.", 406 | "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.", 407 | "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations." 408 | }, 409 | "type": "library", 410 | "autoload": { 411 | "files": [ 412 | "phpseclib/bootstrap.php" 413 | ], 414 | "psr-4": { 415 | "phpseclib\\": "phpseclib/" 416 | } 417 | }, 418 | "notification-url": "https://packagist.org/downloads/", 419 | "license": [ 420 | "MIT" 421 | ], 422 | "authors": [ 423 | { 424 | "name": "Jim Wigginton", 425 | "email": "terrafrost@php.net", 426 | "role": "Lead Developer" 427 | }, 428 | { 429 | "name": "Patrick Monnerat", 430 | "email": "pm@datasphere.ch", 431 | "role": "Developer" 432 | }, 433 | { 434 | "name": "Andreas Fischer", 435 | "email": "bantu@phpbb.com", 436 | "role": "Developer" 437 | }, 438 | { 439 | "name": "Hans-Jürgen Petrich", 440 | "email": "petrich@tronic-media.com", 441 | "role": "Developer" 442 | }, 443 | { 444 | "name": "Graham Campbell", 445 | "email": "graham@alt-three.com", 446 | "role": "Developer" 447 | } 448 | ], 449 | "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.", 450 | "homepage": "http://phpseclib.sourceforge.net", 451 | "keywords": [ 452 | "BigInteger", 453 | "aes", 454 | "asn.1", 455 | "asn1", 456 | "blowfish", 457 | "crypto", 458 | "cryptography", 459 | "encryption", 460 | "rsa", 461 | "security", 462 | "sftp", 463 | "signature", 464 | "signing", 465 | "ssh", 466 | "twofish", 467 | "x.509", 468 | "x509" 469 | ], 470 | "support": { 471 | "issues": "https://github.com/phpseclib/phpseclib/issues", 472 | "source": "https://github.com/phpseclib/phpseclib/tree/2.0.37" 473 | }, 474 | "funding": [ 475 | { 476 | "url": "https://github.com/terrafrost", 477 | "type": "github" 478 | }, 479 | { 480 | "url": "https://www.patreon.com/phpseclib", 481 | "type": "patreon" 482 | }, 483 | { 484 | "url": "https://tidelift.com/funding/github/packagist/phpseclib/phpseclib", 485 | "type": "tidelift" 486 | } 487 | ], 488 | "time": "2022-04-04T04:57:45+00:00" 489 | }, 490 | { 491 | "name": "psr/http-client", 492 | "version": "1.0.1", 493 | "source": { 494 | "type": "git", 495 | "url": "https://github.com/php-fig/http-client.git", 496 | "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" 497 | }, 498 | "dist": { 499 | "type": "zip", 500 | "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", 501 | "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", 502 | "shasum": "" 503 | }, 504 | "require": { 505 | "php": "^7.0 || ^8.0", 506 | "psr/http-message": "^1.0" 507 | }, 508 | "type": "library", 509 | "extra": { 510 | "branch-alias": { 511 | "dev-master": "1.0.x-dev" 512 | } 513 | }, 514 | "autoload": { 515 | "psr-4": { 516 | "Psr\\Http\\Client\\": "src/" 517 | } 518 | }, 519 | "notification-url": "https://packagist.org/downloads/", 520 | "license": [ 521 | "MIT" 522 | ], 523 | "authors": [ 524 | { 525 | "name": "PHP-FIG", 526 | "homepage": "http://www.php-fig.org/" 527 | } 528 | ], 529 | "description": "Common interface for HTTP clients", 530 | "homepage": "https://github.com/php-fig/http-client", 531 | "keywords": [ 532 | "http", 533 | "http-client", 534 | "psr", 535 | "psr-18" 536 | ], 537 | "support": { 538 | "source": "https://github.com/php-fig/http-client/tree/master" 539 | }, 540 | "time": "2020-06-29T06:28:15+00:00" 541 | }, 542 | { 543 | "name": "psr/http-factory", 544 | "version": "1.0.1", 545 | "source": { 546 | "type": "git", 547 | "url": "https://github.com/php-fig/http-factory.git", 548 | "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" 549 | }, 550 | "dist": { 551 | "type": "zip", 552 | "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", 553 | "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", 554 | "shasum": "" 555 | }, 556 | "require": { 557 | "php": ">=7.0.0", 558 | "psr/http-message": "^1.0" 559 | }, 560 | "type": "library", 561 | "extra": { 562 | "branch-alias": { 563 | "dev-master": "1.0.x-dev" 564 | } 565 | }, 566 | "autoload": { 567 | "psr-4": { 568 | "Psr\\Http\\Message\\": "src/" 569 | } 570 | }, 571 | "notification-url": "https://packagist.org/downloads/", 572 | "license": [ 573 | "MIT" 574 | ], 575 | "authors": [ 576 | { 577 | "name": "PHP-FIG", 578 | "homepage": "http://www.php-fig.org/" 579 | } 580 | ], 581 | "description": "Common interfaces for PSR-7 HTTP message factories", 582 | "keywords": [ 583 | "factory", 584 | "http", 585 | "message", 586 | "psr", 587 | "psr-17", 588 | "psr-7", 589 | "request", 590 | "response" 591 | ], 592 | "support": { 593 | "source": "https://github.com/php-fig/http-factory/tree/master" 594 | }, 595 | "time": "2019-04-30T12:38:16+00:00" 596 | }, 597 | { 598 | "name": "psr/http-message", 599 | "version": "1.0.1", 600 | "source": { 601 | "type": "git", 602 | "url": "https://github.com/php-fig/http-message.git", 603 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" 604 | }, 605 | "dist": { 606 | "type": "zip", 607 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", 608 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", 609 | "shasum": "" 610 | }, 611 | "require": { 612 | "php": ">=5.3.0" 613 | }, 614 | "type": "library", 615 | "extra": { 616 | "branch-alias": { 617 | "dev-master": "1.0.x-dev" 618 | } 619 | }, 620 | "autoload": { 621 | "psr-4": { 622 | "Psr\\Http\\Message\\": "src/" 623 | } 624 | }, 625 | "notification-url": "https://packagist.org/downloads/", 626 | "license": [ 627 | "MIT" 628 | ], 629 | "authors": [ 630 | { 631 | "name": "PHP-FIG", 632 | "homepage": "http://www.php-fig.org/" 633 | } 634 | ], 635 | "description": "Common interface for HTTP messages", 636 | "homepage": "https://github.com/php-fig/http-message", 637 | "keywords": [ 638 | "http", 639 | "http-message", 640 | "psr", 641 | "psr-7", 642 | "request", 643 | "response" 644 | ], 645 | "support": { 646 | "source": "https://github.com/php-fig/http-message/tree/master" 647 | }, 648 | "time": "2016-08-06T14:39:51+00:00" 649 | }, 650 | { 651 | "name": "ralouphie/getallheaders", 652 | "version": "3.0.3", 653 | "source": { 654 | "type": "git", 655 | "url": "https://github.com/ralouphie/getallheaders.git", 656 | "reference": "120b605dfeb996808c31b6477290a714d356e822" 657 | }, 658 | "dist": { 659 | "type": "zip", 660 | "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", 661 | "reference": "120b605dfeb996808c31b6477290a714d356e822", 662 | "shasum": "" 663 | }, 664 | "require": { 665 | "php": ">=5.6" 666 | }, 667 | "require-dev": { 668 | "php-coveralls/php-coveralls": "^2.1", 669 | "phpunit/phpunit": "^5 || ^6.5" 670 | }, 671 | "type": "library", 672 | "autoload": { 673 | "files": [ 674 | "src/getallheaders.php" 675 | ] 676 | }, 677 | "notification-url": "https://packagist.org/downloads/", 678 | "license": [ 679 | "MIT" 680 | ], 681 | "authors": [ 682 | { 683 | "name": "Ralph Khattar", 684 | "email": "ralph.khattar@gmail.com" 685 | } 686 | ], 687 | "description": "A polyfill for getallheaders.", 688 | "support": { 689 | "issues": "https://github.com/ralouphie/getallheaders/issues", 690 | "source": "https://github.com/ralouphie/getallheaders/tree/develop" 691 | }, 692 | "time": "2019-03-08T08:55:37+00:00" 693 | }, 694 | { 695 | "name": "simplito/bigint-wrapper-php", 696 | "version": "1.0.0", 697 | "source": { 698 | "type": "git", 699 | "url": "https://github.com/simplito/bigint-wrapper-php.git", 700 | "reference": "cf21ec76d33f103add487b3eadbd9f5033a25930" 701 | }, 702 | "dist": { 703 | "type": "zip", 704 | "url": "https://api.github.com/repos/simplito/bigint-wrapper-php/zipball/cf21ec76d33f103add487b3eadbd9f5033a25930", 705 | "reference": "cf21ec76d33f103add487b3eadbd9f5033a25930", 706 | "shasum": "" 707 | }, 708 | "type": "library", 709 | "autoload": { 710 | "psr-4": { 711 | "BI\\": "lib/" 712 | } 713 | }, 714 | "notification-url": "https://packagist.org/downloads/", 715 | "license": [ 716 | "MIT" 717 | ], 718 | "authors": [ 719 | { 720 | "name": "Simplito Team", 721 | "email": "s.smyczynski@simplito.com", 722 | "homepage": "https://simplito.com" 723 | } 724 | ], 725 | "description": "Common interface for php_gmp and php_bcmath modules", 726 | "support": { 727 | "issues": "https://github.com/simplito/bigint-wrapper-php/issues", 728 | "source": "https://github.com/simplito/bigint-wrapper-php/tree/1.0.0" 729 | }, 730 | "time": "2018-02-27T12:38:08+00:00" 731 | }, 732 | { 733 | "name": "simplito/bn-php", 734 | "version": "1.1.2", 735 | "source": { 736 | "type": "git", 737 | "url": "https://github.com/simplito/bn-php.git", 738 | "reference": "e852fcd27e4acbc32459606d7606e45a85e42465" 739 | }, 740 | "dist": { 741 | "type": "zip", 742 | "url": "https://api.github.com/repos/simplito/bn-php/zipball/e852fcd27e4acbc32459606d7606e45a85e42465", 743 | "reference": "e852fcd27e4acbc32459606d7606e45a85e42465", 744 | "shasum": "" 745 | }, 746 | "require": { 747 | "simplito/bigint-wrapper-php": "~1.0.0" 748 | }, 749 | "require-dev": { 750 | "phpunit/phpunit": "*" 751 | }, 752 | "type": "library", 753 | "autoload": { 754 | "psr-4": { 755 | "BN\\": "lib/" 756 | } 757 | }, 758 | "notification-url": "https://packagist.org/downloads/", 759 | "license": [ 760 | "MIT" 761 | ], 762 | "authors": [ 763 | { 764 | "name": "Simplito Team", 765 | "email": "s.smyczynski@simplito.com", 766 | "homepage": "https://simplito.com" 767 | } 768 | ], 769 | "description": "Big number implementation compatible with bn.js", 770 | "support": { 771 | "issues": "https://github.com/simplito/bn-php/issues", 772 | "source": "https://github.com/simplito/bn-php/tree/1.1.2" 773 | }, 774 | "time": "2018-04-12T11:07:43+00:00" 775 | }, 776 | { 777 | "name": "simplito/elliptic-php", 778 | "version": "1.0.9", 779 | "source": { 780 | "type": "git", 781 | "url": "https://github.com/simplito/elliptic-php.git", 782 | "reference": "18a72b837b845bf9a2ad2c0050eaf864a22b7550" 783 | }, 784 | "dist": { 785 | "type": "zip", 786 | "url": "https://api.github.com/repos/simplito/elliptic-php/zipball/18a72b837b845bf9a2ad2c0050eaf864a22b7550", 787 | "reference": "18a72b837b845bf9a2ad2c0050eaf864a22b7550", 788 | "shasum": "" 789 | }, 790 | "require": { 791 | "ext-gmp": "*", 792 | "simplito/bn-php": "~1.1.0" 793 | }, 794 | "require-dev": { 795 | "phpbench/phpbench": "@dev", 796 | "phpunit/phpunit": "*" 797 | }, 798 | "type": "library", 799 | "autoload": { 800 | "psr-4": { 801 | "Elliptic\\": "lib/" 802 | } 803 | }, 804 | "notification-url": "https://packagist.org/downloads/", 805 | "license": [ 806 | "MIT" 807 | ], 808 | "authors": [ 809 | { 810 | "name": "Simplito Team", 811 | "email": "s.smyczynski@simplito.com", 812 | "homepage": "https://simplito.com" 813 | } 814 | ], 815 | "description": "Fast elliptic curve cryptography", 816 | "homepage": "https://github.com/simplito/elliptic-php", 817 | "keywords": [ 818 | "Curve25519", 819 | "ECDSA", 820 | "Ed25519", 821 | "EdDSA", 822 | "cryptography", 823 | "curve", 824 | "curve25519-weier", 825 | "ecc", 826 | "ecdh", 827 | "elliptic", 828 | "nistp192", 829 | "nistp224", 830 | "nistp256", 831 | "nistp384", 832 | "nistp521", 833 | "secp256k1" 834 | ], 835 | "support": { 836 | "issues": "https://github.com/simplito/elliptic-php/issues", 837 | "source": "https://github.com/simplito/elliptic-php/tree/1.0.9" 838 | }, 839 | "time": "2021-10-19T08:42:33+00:00" 840 | }, 841 | { 842 | "name": "symfony/deprecation-contracts", 843 | "version": "v2.5.1", 844 | "source": { 845 | "type": "git", 846 | "url": "https://github.com/symfony/deprecation-contracts.git", 847 | "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" 848 | }, 849 | "dist": { 850 | "type": "zip", 851 | "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", 852 | "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", 853 | "shasum": "" 854 | }, 855 | "require": { 856 | "php": ">=7.1" 857 | }, 858 | "type": "library", 859 | "extra": { 860 | "branch-alias": { 861 | "dev-main": "2.5-dev" 862 | }, 863 | "thanks": { 864 | "name": "symfony/contracts", 865 | "url": "https://github.com/symfony/contracts" 866 | } 867 | }, 868 | "autoload": { 869 | "files": [ 870 | "function.php" 871 | ] 872 | }, 873 | "notification-url": "https://packagist.org/downloads/", 874 | "license": [ 875 | "MIT" 876 | ], 877 | "authors": [ 878 | { 879 | "name": "Nicolas Grekas", 880 | "email": "p@tchwork.com" 881 | }, 882 | { 883 | "name": "Symfony Community", 884 | "homepage": "https://symfony.com/contributors" 885 | } 886 | ], 887 | "description": "A generic function and convention to trigger deprecation notices", 888 | "homepage": "https://symfony.com", 889 | "support": { 890 | "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.1" 891 | }, 892 | "funding": [ 893 | { 894 | "url": "https://symfony.com/sponsor", 895 | "type": "custom" 896 | }, 897 | { 898 | "url": "https://github.com/fabpot", 899 | "type": "github" 900 | }, 901 | { 902 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", 903 | "type": "tidelift" 904 | } 905 | ], 906 | "time": "2022-01-02T09:53:40+00:00" 907 | }, 908 | { 909 | "name": "symfony/polyfill-mbstring", 910 | "version": "v1.25.0", 911 | "source": { 912 | "type": "git", 913 | "url": "https://github.com/symfony/polyfill-mbstring.git", 914 | "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825" 915 | }, 916 | "dist": { 917 | "type": "zip", 918 | "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825", 919 | "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825", 920 | "shasum": "" 921 | }, 922 | "require": { 923 | "php": ">=7.1" 924 | }, 925 | "provide": { 926 | "ext-mbstring": "*" 927 | }, 928 | "suggest": { 929 | "ext-mbstring": "For best performance" 930 | }, 931 | "type": "library", 932 | "extra": { 933 | "branch-alias": { 934 | "dev-main": "1.23-dev" 935 | }, 936 | "thanks": { 937 | "name": "symfony/polyfill", 938 | "url": "https://github.com/symfony/polyfill" 939 | } 940 | }, 941 | "autoload": { 942 | "files": [ 943 | "bootstrap.php" 944 | ], 945 | "psr-4": { 946 | "Symfony\\Polyfill\\Mbstring\\": "" 947 | } 948 | }, 949 | "notification-url": "https://packagist.org/downloads/", 950 | "license": [ 951 | "MIT" 952 | ], 953 | "authors": [ 954 | { 955 | "name": "Nicolas Grekas", 956 | "email": "p@tchwork.com" 957 | }, 958 | { 959 | "name": "Symfony Community", 960 | "homepage": "https://symfony.com/contributors" 961 | } 962 | ], 963 | "description": "Symfony polyfill for the Mbstring extension", 964 | "homepage": "https://symfony.com", 965 | "keywords": [ 966 | "compatibility", 967 | "mbstring", 968 | "polyfill", 969 | "portable", 970 | "shim" 971 | ], 972 | "support": { 973 | "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.25.0" 974 | }, 975 | "funding": [ 976 | { 977 | "url": "https://symfony.com/sponsor", 978 | "type": "custom" 979 | }, 980 | { 981 | "url": "https://github.com/fabpot", 982 | "type": "github" 983 | }, 984 | { 985 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", 986 | "type": "tidelift" 987 | } 988 | ], 989 | "time": "2021-11-30T18:21:41+00:00" 990 | }, 991 | { 992 | "name": "web3p/ethereum-tx", 993 | "version": "0.4.3", 994 | "source": { 995 | "type": "git", 996 | "url": "https://github.com/web3p/ethereum-tx.git", 997 | "reference": "8dc1adc10ae45ac440c43ac32a3c5adf63ed8cef" 998 | }, 999 | "dist": { 1000 | "type": "zip", 1001 | "url": "https://api.github.com/repos/web3p/ethereum-tx/zipball/8dc1adc10ae45ac440c43ac32a3c5adf63ed8cef", 1002 | "reference": "8dc1adc10ae45ac440c43ac32a3c5adf63ed8cef", 1003 | "shasum": "" 1004 | }, 1005 | "require": { 1006 | "kornrunner/keccak": "~1", 1007 | "php": "^7.1|^8.0", 1008 | "simplito/elliptic-php": "~1.0.6", 1009 | "web3p/ethereum-util": "~0.1.3", 1010 | "web3p/rlp": "0.3.4" 1011 | }, 1012 | "require-dev": { 1013 | "phpunit/phpunit": "~7|~8.0" 1014 | }, 1015 | "type": "library", 1016 | "autoload": { 1017 | "psr-4": { 1018 | "Web3p\\EthereumTx\\": "src/" 1019 | } 1020 | }, 1021 | "notification-url": "https://packagist.org/downloads/", 1022 | "license": [ 1023 | "MIT" 1024 | ], 1025 | "authors": [ 1026 | { 1027 | "name": "sc0Vu", 1028 | "email": "alk03073135@gmail.com" 1029 | } 1030 | ], 1031 | "description": "Ethereum transaction library in PHP.", 1032 | "support": { 1033 | "issues": "https://github.com/web3p/ethereum-tx/issues", 1034 | "source": "https://github.com/web3p/ethereum-tx/tree/0.4.3" 1035 | }, 1036 | "time": "2021-09-01T05:13:20+00:00" 1037 | }, 1038 | { 1039 | "name": "web3p/ethereum-util", 1040 | "version": "0.1.3", 1041 | "source": { 1042 | "type": "git", 1043 | "url": "https://github.com/web3p/ethereum-util.git", 1044 | "reference": "77a860f35028eae57cd7e7a044ab6c11ffe1ad9e" 1045 | }, 1046 | "dist": { 1047 | "type": "zip", 1048 | "url": "https://api.github.com/repos/web3p/ethereum-util/zipball/77a860f35028eae57cd7e7a044ab6c11ffe1ad9e", 1049 | "reference": "77a860f35028eae57cd7e7a044ab6c11ffe1ad9e", 1050 | "shasum": "" 1051 | }, 1052 | "require": { 1053 | "kornrunner/keccak": "~1", 1054 | "php": "^7.1 | ^8.0", 1055 | "simplito/elliptic-php": "~1.0.6" 1056 | }, 1057 | "require-dev": { 1058 | "phpunit/phpunit": "~7 | ~8.0" 1059 | }, 1060 | "type": "library", 1061 | "autoload": { 1062 | "psr-4": { 1063 | "Web3p\\EthereumUtil\\": "src/" 1064 | } 1065 | }, 1066 | "notification-url": "https://packagist.org/downloads/", 1067 | "license": [ 1068 | "MIT" 1069 | ], 1070 | "authors": [ 1071 | { 1072 | "name": "sc0Vu", 1073 | "email": "alk03073135@gmail.com" 1074 | } 1075 | ], 1076 | "description": "A collection of utility functions for Ethereum written in PHP.", 1077 | "support": { 1078 | "issues": "https://github.com/web3p/ethereum-util/issues", 1079 | "source": "https://github.com/web3p/ethereum-util/tree/0.1.3" 1080 | }, 1081 | "time": "2021-06-05T05:35:13+00:00" 1082 | }, 1083 | { 1084 | "name": "web3p/rlp", 1085 | "version": "0.3.4", 1086 | "source": { 1087 | "type": "git", 1088 | "url": "https://github.com/web3p/rlp.git", 1089 | "reference": "1653af23142863b490bdf22c6d0335bdb588c983" 1090 | }, 1091 | "dist": { 1092 | "type": "zip", 1093 | "url": "https://api.github.com/repos/web3p/rlp/zipball/1653af23142863b490bdf22c6d0335bdb588c983", 1094 | "reference": "1653af23142863b490bdf22c6d0335bdb588c983", 1095 | "shasum": "" 1096 | }, 1097 | "require": { 1098 | "ext-mbstring": "*", 1099 | "php": "^7.1 | ^8.0" 1100 | }, 1101 | "require-dev": { 1102 | "phpunit/phpunit": "~7|~8.0" 1103 | }, 1104 | "type": "library", 1105 | "autoload": { 1106 | "psr-4": { 1107 | "Web3p\\RLP\\": "src/" 1108 | } 1109 | }, 1110 | "notification-url": "https://packagist.org/downloads/", 1111 | "license": [ 1112 | "MIT" 1113 | ], 1114 | "authors": [ 1115 | { 1116 | "name": "sc0Vu", 1117 | "email": "alk03073135@gmail.com" 1118 | } 1119 | ], 1120 | "description": "Recursive Length Prefix Encoding in PHP.", 1121 | "support": { 1122 | "issues": "https://github.com/web3p/rlp/issues", 1123 | "source": "https://github.com/web3p/rlp/tree/0.3.4" 1124 | }, 1125 | "time": "2021-08-30T10:22:03+00:00" 1126 | }, 1127 | { 1128 | "name": "web3p/web3.php", 1129 | "version": "0.1.6", 1130 | "source": { 1131 | "type": "git", 1132 | "url": "https://github.com/web3p/web3.php.git", 1133 | "reference": "2eafffbbe50b79b819088c6a72baf3780d672e11" 1134 | }, 1135 | "dist": { 1136 | "type": "zip", 1137 | "url": "https://api.github.com/repos/web3p/web3.php/zipball/2eafffbbe50b79b819088c6a72baf3780d672e11", 1138 | "reference": "2eafffbbe50b79b819088c6a72baf3780d672e11", 1139 | "shasum": "" 1140 | }, 1141 | "require": { 1142 | "ext-mbstring": "*", 1143 | "guzzlehttp/guzzle": "^6.3|^7.0", 1144 | "kornrunner/keccak": "~1.0", 1145 | "php": "^7.2|^8.0", 1146 | "phpseclib/phpseclib": "~2.0.30" 1147 | }, 1148 | "require-dev": { 1149 | "phpunit/phpunit": "~8.0|~9.0" 1150 | }, 1151 | "type": "library", 1152 | "autoload": { 1153 | "psr-4": { 1154 | "Web3\\": "src/" 1155 | } 1156 | }, 1157 | "notification-url": "https://packagist.org/downloads/", 1158 | "license": [ 1159 | "MIT" 1160 | ], 1161 | "authors": [ 1162 | { 1163 | "name": "sc0Vu", 1164 | "email": "alk03073135@gmail.com" 1165 | } 1166 | ], 1167 | "description": "Ethereum web3 interface.", 1168 | "support": { 1169 | "issues": "https://github.com/web3p/web3.php/issues", 1170 | "source": "https://github.com/web3p/web3.php/tree/0.1.6" 1171 | }, 1172 | "time": "2022-03-07T03:26:51+00:00" 1173 | } 1174 | ], 1175 | "packages-dev": [], 1176 | "aliases": [], 1177 | "minimum-stability": "stable", 1178 | "stability-flags": [], 1179 | "prefer-stable": false, 1180 | "prefer-lowest": false, 1181 | "platform": { 1182 | "php": "^7.1|^8.0", 1183 | "ext-mbstring": "*" 1184 | }, 1185 | "platform-dev": [], 1186 | "plugin-api-version": "2.2.0" 1187 | } 1188 | -------------------------------------------------------------------------------- /erc20.php: -------------------------------------------------------------------------------- 1 | provider, $erc20Json->abi); 15 | 16 | echo 'Start to deploy erc20 contract' . PHP_EOL; 17 | 18 | // deploy erc20 token 19 | $data = $contract->bytecode($erc20Json->bytecode)->getData('Web3Token', 'W3'); 20 | $nonce = getNonce($eth, $ownAccount); 21 | $transaction = new Transaction([ 22 | 'nonce' => '0x' . $nonce->toHex(), 23 | 'gas' => '0xfd240', 24 | 'gasPrice' => '0x' . Utils::toWei('5', 'gwei')->toHex(), 25 | 'data' => '0x' . $data, 26 | 'chainId' => $chainId 27 | ]); 28 | $transaction->sign($testPrivateKey); 29 | $txHash = ''; 30 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $mainAccount, $ownAccount, &$txHash) { 31 | if ($err !== null) { 32 | echo 'Error: ' . $err->getMessage(); 33 | return; 34 | } 35 | echo 'Tx hash: ' . $transaction . PHP_EOL; 36 | $txHash = $transaction; 37 | }); 38 | 39 | $transaction = confirmTx($eth, $txHash); 40 | if (!$transaction) { 41 | throw new Error('Transaction was not confirmed.'); 42 | } 43 | $contractAddress = $transaction->contractAddress; 44 | echo "\nContract has been created:) block number: " . $transaction->blockNumber . PHP_EOL . "Contract address: " . $contractAddress . PHP_EOL; 45 | $contract = $contract->at($contractAddress); 46 | $estimatedGas = '0x200b20'; 47 | 48 | $contract->at($contractAddress)->estimateGas('transfer', $mainAccount, 10, [ 49 | 'from' => $ownAccount, 50 | ], function ($err, $result) use (&$estimatedGas) { 51 | if ($err !== null) { 52 | throw $err; 53 | } 54 | $estimatedGas = '0x' . $result->toHex(); 55 | }); 56 | $data = $contract->getData('transfer', $mainAccount, 10); 57 | $nonce = $nonce->add(Utils::toBn(1)); 58 | $transaction = new Transaction([ 59 | 'nonce' => '0x' . $nonce->toHex(), 60 | 'to' => $contractAddress, 61 | 'gas' => $estimatedGas, 62 | 'gasPrice' => '0x' . Utils::toWei('5', 'gwei')->toHex(), 63 | 'data' => '0x' . $data, 64 | 'chainId' => $chainId 65 | ]); 66 | $transaction->sign($testPrivateKey); 67 | $txHash = ''; 68 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $mainAccount, $ownAccount, &$txHash) { 69 | if ($err !== null) { 70 | echo 'Error: ' . $err->getMessage(); 71 | return; 72 | } 73 | echo 'Tx hash: ' . $transaction . PHP_EOL; 74 | $txHash = $transaction; 75 | }); 76 | $transaction = confirmTx($eth, $txHash); 77 | if (!$transaction) { 78 | throw new Error('Transaction was not confirmed.'); 79 | } 80 | 81 | $contract->call('balanceOf', $ownAccount, function ($err, $result) { 82 | if ($err !== null) { 83 | throw $err; 84 | } 85 | if ($result) { 86 | echo 'Token balance of signer: ' . $result[0]->toHex() . PHP_EOL; 87 | } 88 | }); 89 | 90 | $contract->call('balanceOf', $mainAccount, function ($err, $result) { 91 | if ($err !== null) { 92 | throw $err; 93 | } 94 | if ($result) { 95 | echo 'Token balance of other account: ' . $result[0]->toHex() . PHP_EOL; 96 | } 97 | }); 98 | -------------------------------------------------------------------------------- /exampleBase.php: -------------------------------------------------------------------------------- 1 | eth; 11 | 12 | // BSC chain id, remember to set the right chain id 13 | // Find chain id here: https://chainlist.org/ 14 | $chainId = 56; 15 | 16 | /** 17 | * erc20Json 18 | * Openzeppelin abi from https://github.com/OpenZeppelin/openzeppelin-contracts 19 | */ 20 | $erc20JsonFile = file_get_contents($dir . '/ERC20.json'); 21 | $erc20Json = json_decode($erc20JsonFile); 22 | 23 | /** 24 | * erc721Json 25 | * Openzeppelin abi from https://github.com/OpenZeppelin/openzeppelin-contracts 26 | */ 27 | $erc721JsonFile = file_get_contents($dir . '/ERC721.json'); 28 | $erc721Json = json_decode($erc721JsonFile); 29 | 30 | /** 31 | * testPrivateKey 32 | * Never use this in real world 33 | * 34 | * @var string 35 | */ 36 | $testPrivateKey = ''; 37 | 38 | /** 39 | * testAddress 40 | * Never use this in real world 41 | * 42 | * @var string 43 | */ 44 | $testAddress = ''; 45 | 46 | /** 47 | * testAddress2 48 | * Never use this in real world 49 | * 50 | * @var string 51 | */ 52 | $testAddress2 = ''; 53 | 54 | /** 55 | * settings for testing uniswap based DEX 56 | * 57 | * $testUNIAbi 58 | * uniswap router abi 59 | * 60 | * @var string 61 | * 62 | * $testUNIRouterAddress 63 | * uniswap router address 64 | * 65 | * @var string 66 | */ 67 | $uniV2JsonFile = file_get_contents($dir . '/UNIV2Router.json'); 68 | $uniV2Json = json_decode($uniV2JsonFile); 69 | $testUNIRouterAddress = '0x10ed43c718714eb63d5aa57b78b54704e256024e'; -------------------------------------------------------------------------------- /nft.php: -------------------------------------------------------------------------------- 1 | provider, $erc721Json->abi); 11 | $ownAccount = $testAddress; 12 | $ownBalance = getBalance($eth, $ownAccount); 13 | 14 | echo 'Start to deploy erc721 contract' . PHP_EOL; 15 | 16 | // deploy erc721 token 17 | $data = $contract->bytecode($erc721Json->bytecode)->getData("Web3Identity", "W3"); 18 | $nonce = getNonce($eth, $ownAccount); 19 | $gasPrice = '0x' . Utils::toWei('5', 'gwei')->toHex(); 20 | $transaction = new Transaction([ 21 | 'nonce' => '0x' . $nonce->toHex(), 22 | 'gas' => 3000000, 23 | 'gasPrice' => $gasPrice, 24 | 'data' => '0x' . $data, 25 | 'chainId' => $chainId 26 | ]); 27 | $transaction->sign($testPrivateKey); 28 | $txHash = ''; 29 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $ownAccount, &$txHash) { 30 | if ($err !== null) { 31 | echo 'Error: ' . $err->getMessage(); 32 | return; 33 | } 34 | echo 'Deploy tx hash: ' . $transaction . PHP_EOL; 35 | $txHash = $transaction; 36 | }); 37 | 38 | $transaction = confirmTx($eth, $txHash); 39 | if (!$transaction) { 40 | throw new Error('Transaction was not confirmed.'); 41 | } 42 | 43 | $contractAddress = $transaction->contractAddress; 44 | echo "\nContract has been created:) block number: " . $transaction->blockNumber . PHP_EOL . "Contract address: " . $contractAddress . PHP_EOL; 45 | $contract = $contract->at($contractAddress); 46 | 47 | $contract->at($contractAddress)->estimateGas('mint', $ownAccount, 1, 'https://avatars.githubusercontent.com/u/34670362?s=400', [ 48 | 'from' => $ownAccount, 49 | ], function ($err, $result) use (&$estimatedGas) { 50 | if ($err !== null) { 51 | throw $err; 52 | } 53 | $estimatedGas = '0x' . $result->toHex(); 54 | }); 55 | $data = $contract->getData('mint', $ownAccount, 1, 'https://avatars.githubusercontent.com/u/34670362?s=400'); 56 | $nonce = $nonce->add(Utils::toBn(1)); 57 | $transaction = new Transaction([ 58 | 'nonce' => '0x' . $nonce->toHex(), 59 | 'to' => $contractAddress, 60 | 'gas' => $estimatedGas, 61 | 'gasPrice' => $gasPrice, 62 | 'data' => '0x' . $data, 63 | 'chainId' => $chainId 64 | ]); 65 | $transaction->sign($testPrivateKey); 66 | $txHash = ''; 67 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $ownAccount, &$txHash) { 68 | if ($err !== null) { 69 | echo 'Error: ' . $err->getMessage(); 70 | return; 71 | } 72 | echo 'Mint tx hash: ' . $transaction . PHP_EOL; 73 | $txHash = $transaction; 74 | }); 75 | 76 | $transaction = confirmTx($eth, $txHash); 77 | if (!$transaction) { 78 | throw new Error('Transaction was not confirmed.'); 79 | } 80 | 81 | echo "Minted!!!" . PHP_EOL; -------------------------------------------------------------------------------- /swap.php: -------------------------------------------------------------------------------- 1 | net); 12 | 13 | $contract = new Contract($web3->provider, $uniV2Json->abi); 14 | $ownAccount = $testAddress; 15 | 16 | echo 'Start to swap eth to tokens' . PHP_EOL; 17 | 18 | // swap eth to token 19 | $contract = $contract->at($testUNIRouterAddress); 20 | $amountIn = Utils::toWei('0.01', 'ether'); 21 | $amountOut; 22 | $path = [ 23 | '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', 24 | '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984' 25 | ]; 26 | 27 | // get swap amounts 28 | $getAmountsOutRes = getUniV2AmountsOut($contract, $amountIn, $path, [ 29 | 'from' => $testAddress 30 | ]); 31 | echo 'Expect token output: ' . $getAmountsOutRes[1]->toString() . PHP_EOL; 32 | $amountOut = $getAmountsOutRes[1]; 33 | 34 | $estimatedGas; 35 | $gasPrice = '0x' . Utils::toWei('50', 'gwei')->toHex(); 36 | $contract->estimateGas('swapExactETHForTokens', $amountOut, $path, $testAddress, 1700000000, [ 37 | 'from' => $testAddress, 38 | 'value' => '0x' . $amountIn->toHex() 39 | ], function ($err, $result) use (&$estimatedGas) { 40 | if ($err !== null) { 41 | throw $err; 42 | } 43 | $estimatedGas = $result->multiply(Utils::toBn(2)); 44 | }); 45 | $data = $contract->getData('swapExactETHForTokens', $amountOut, $path, $testAddress, 1700000000); 46 | $nonce = getNonce($eth, $ownAccount); 47 | $transaction = new Transaction([ 48 | 'nonce' => '0x' . $nonce->toHex(), 49 | 'gas' => '0x' . $estimatedGas->toHex(), 50 | 'gasPrice' => $gasPrice, 51 | 'data' => '0x' . $data, 52 | 'value' => '0x' . $amountIn->toHex(), 53 | 'chainId' => $chainId, 54 | 'to' => $testUNIRouterAddress 55 | ]); 56 | $transaction->sign($testPrivateKey); 57 | $txHash = ''; 58 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $ownAccount, &$txHash) { 59 | if ($err !== null) { 60 | echo 'Error: ' . $err->getMessage(); 61 | return; 62 | } 63 | echo 'Swap eth to tokens tx hash: ' . $transaction . PHP_EOL; 64 | $txHash = $transaction; 65 | }); 66 | 67 | $transaction = confirmTx($eth, $txHash); 68 | if (!$transaction) { 69 | throw new Error('Transaction was not confirmed.'); 70 | } 71 | 72 | echo "Transaction was confirmed, let's swap back to eth" . PHP_EOL; 73 | $token = new Contract($web3->provider, $erc20Json->abi); 74 | $token = $token->at($path[1]); 75 | 76 | // swap amountIn and amountOut 77 | $tmp = $amountIn; 78 | $amountIn = $amountOut; 79 | $amountOut = $tmp; 80 | 81 | $allowance; 82 | $token->call('allowance', $testAddress, $testUNIRouterAddress, [ 83 | 'from' => $testAddress 84 | ], function ($err, $result) use ($path, &$amountOut, &$allowance) { 85 | if ($err !== null) { 86 | throw $err; 87 | } 88 | if ($result && count($result) > 0) { 89 | $allowance = $result[0]; 90 | } 91 | }); 92 | 93 | // approve 94 | if ($allowance->compare($amountIn) < 0) { 95 | $estimatedApproveGas; 96 | $token->estimateGas('approve', $testUNIRouterAddress, $amountIn, [ 97 | 'from' => $testAddress, 98 | ], function ($err, $result) use (&$estimatedApproveGas) { 99 | if ($err !== null) { 100 | throw $err; 101 | } 102 | $estimatedApproveGas = $result->multiply(Utils::toBn(2)); 103 | }); 104 | 105 | $data = $token->getData('approve', $testUNIRouterAddress, $amountIn); 106 | $nonce = $nonce->add(Utils::toBn(1)); 107 | $transaction = new Transaction([ 108 | 'nonce' => '0x' . $nonce->toHex(), 109 | 'gas' => '0x' . $estimatedApproveGas->toHex(), 110 | 'gasPrice' => $gasPrice, 111 | 'data' => '0x' . $data, 112 | 'chainId' => $chainId, 113 | 'to' => $path[1] 114 | ]); 115 | $transaction->sign($testPrivateKey); 116 | $txHash = ''; 117 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $ownAccount, &$txHash) { 118 | if ($err !== null) { 119 | echo 'Error: ' . $err->getMessage(); 120 | return; 121 | } 122 | echo 'Approve tx hash: ' . $transaction . PHP_EOL; 123 | $txHash = $transaction; 124 | }); 125 | 126 | $transaction = confirmTx($eth, $txHash); 127 | if (!$transaction) { 128 | throw new Error('Transaction was not confirmed.'); 129 | } 130 | } 131 | 132 | // swap back 133 | $newPath = [ 134 | $path[1], 135 | $path[0] 136 | ]; 137 | 138 | // get swap amounts 139 | $getAmountsOutRes = getUniV2AmountsOut($contract, $amountIn, $newPath, [ 140 | 'from' => $testAddress 141 | ]); 142 | echo 'Expect token output: ' . $getAmountsOutRes[1]->toString() . PHP_EOL; 143 | $amountOut = $getAmountsOutRes[1]; 144 | 145 | $contract->estimateGas('swapExactTokensForETH', $amountIn, $amountOut, $newPath, $testAddress, 1700000000, [ 146 | 'from' => $testAddress 147 | ], function ($err, $result) use (&$estimatedGas) { 148 | if ($err !== null) { 149 | throw $err; 150 | } 151 | $estimatedGas = $result->multiply(Utils::toBn(2)); 152 | }); 153 | 154 | $data = $contract->getData('swapExactTokensForETH', $amountIn, $amountOut, $newPath, $testAddress, 1700000000); 155 | $nonce = $nonce->add(Utils::toBn(1)); 156 | $transaction = new Transaction([ 157 | 'nonce' => '0x' . $nonce->toHex(), 158 | 'gas' => '0x' . $estimatedGas->toHex(), 159 | 'gasPrice' => $gasPrice, 160 | 'data' => '0x' . $data, 161 | 'chainId' => $chainId, 162 | 'to' => $testUNIRouterAddress 163 | ]); 164 | $transaction->sign($testPrivateKey); 165 | $txHash = ''; 166 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $ownAccount, &$txHash) { 167 | if ($err !== null) { 168 | echo 'Error: ' . $err->getMessage(); 169 | return; 170 | } 171 | echo 'Swap tokens to eth tx hash: ' . $transaction . PHP_EOL; 172 | $txHash = $transaction; 173 | }); 174 | $transaction = confirmTx($eth, $txHash); 175 | if (!$transaction) { 176 | throw new Error('Transaction was not confirmed.'); 177 | } 178 | echo "Congratulation! The tokens did swap back to eth!" . PHP_EOL; -------------------------------------------------------------------------------- /swap_tokens.php: -------------------------------------------------------------------------------- 1 | provider, $uniV2Json->abi); 11 | $ownAccount = $testAddress; 12 | $ownBalance; 13 | 14 | // get chain id 15 | $chainId = getChainId($web3->net); 16 | 17 | echo 'Start to swap tokens' . PHP_EOL; 18 | 19 | // swap usdc to dai on polygon 20 | $contract = $contract->at($testUNIRouterAddress); 21 | $path = [ 22 | '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', 23 | '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063' 24 | ]; 25 | $amountIn = Utils::toWei('0.01', 'mwei'); 26 | $amountOut = Utils::toWei('9.6', 'ether'); 27 | $nonce = getNonce($eth, $ownAccount); 28 | 29 | // checkout balance and approved allowance 30 | $token = new Contract($web3->provider, $erc20Json->abi); 31 | $token = $token->at($path[0]); 32 | $allowance; 33 | $token->call('balanceOf', $testAddress, [ 34 | 'from' => $testAddress 35 | ], function ($err, $result) use ($path, &$amountOut, &$ownBalance) { 36 | if ($err !== null) { 37 | throw $err; 38 | } 39 | if ($result && count($result) > 0) { 40 | $ownBalance = $result[0]; 41 | } 42 | }); 43 | 44 | if ($ownBalance->compare($amountIn) < 0) { 45 | throw new Error('Balance not enough'); 46 | } 47 | 48 | $token->call('allowance', $testAddress, $testUNIRouterAddress, [ 49 | 'from' => $testAddress 50 | ], function ($err, $result) use ($path, &$amountOut, &$allowance) { 51 | if ($err !== null) { 52 | throw $err; 53 | } 54 | if ($result && count($result) > 0) { 55 | $allowance = $result[0]; 56 | } 57 | }); 58 | 59 | $gasPrice = '0x' . Utils::toWei('50', 'gwei')->toHex(); 60 | 61 | // approve 62 | if ($allowance->compare($amountIn) < 0) { 63 | $estimatedApproveGas; 64 | $token->estimateGas('approve', $testUNIRouterAddress, $amountIn, [ 65 | 'from' => $testAddress, 66 | ], function ($err, $result) use (&$estimatedApproveGas) { 67 | if ($err !== null) { 68 | throw $err; 69 | } 70 | $estimatedApproveGas = $result->multiply(Utils::toBn(2)); 71 | }); 72 | $data = $token->getData('approve', $testUNIRouterAddress, $amountIn); 73 | $transaction = new Transaction([ 74 | 'nonce' => '0x' . $nonce->toHex(), 75 | 'gas' => '0x' . $estimatedApproveGas->toHex(), 76 | 'gasPrice' => $gasPrice, 77 | 'data' => '0x' . $data, 78 | 'chainId' => $chainId, 79 | 'to' => $path[0] 80 | ]); 81 | $transaction->sign($testPrivateKey); 82 | $txHash = ''; 83 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $ownAccount, &$txHash) { 84 | if ($err !== null) { 85 | echo 'Error: ' . $err->getMessage(); 86 | return; 87 | } 88 | echo 'Approve tx hash: ' . $transaction . PHP_EOL; 89 | $txHash = $transaction; 90 | }); 91 | 92 | $transaction = confirmTx($eth, $txHash); 93 | if (!$transaction) { 94 | throw new Error('Transaction was not confirmed.'); 95 | } 96 | $nonce = $nonce->add(Utils::toBn(1)); 97 | } 98 | 99 | // get swap amounts 100 | $getAmountsOutRes = getUniV2AmountsOut($contract, $amountIn, $path, [ 101 | 'from' => $testAddress 102 | ]); 103 | echo 'Expect token output: ' . $getAmountsOutRes[1]->toString() . PHP_EOL; 104 | $amountOut = $getAmountsOutRes[1]; 105 | 106 | $estimatedGas; 107 | $contract->estimateGas('swapExactTokensForTokens', $amountIn, $amountOut, $path, $testAddress, 1700000000, [ 108 | 'from' => $testAddress 109 | ], function ($err, $result) use (&$estimatedGas) { 110 | if ($err !== null) { 111 | throw $err; 112 | } 113 | if ($result) { 114 | echo 'Estimate gas: ' . $result->toString() . PHP_EOL; 115 | } 116 | $estimatedGas = $result->multiply(Utils::toBn(2)); 117 | }); 118 | $data = $contract->getData('swapExactTokensForTokens', $amountIn, $amountOut, $path, $testAddress, 1700000000); 119 | $nonce = getNonce($eth, $ownAccount); 120 | $transaction = new Transaction([ 121 | 'nonce' => '0x' . $nonce->toHex(), 122 | 'gas' => '0x' . $estimatedGas->toHex(), 123 | 'gasPrice' => $gasPrice, 124 | 'data' => '0x' . $data, 125 | 'chainId' => $chainId, 126 | 'to' => $testUNIRouterAddress 127 | ]); 128 | $transaction->sign($testPrivateKey); 129 | $txHash = ''; 130 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $ownAccount, &$txHash) { 131 | if ($err !== null) { 132 | throw $err; 133 | } 134 | echo 'Swap tokens tx hash: ' . $transaction . PHP_EOL; 135 | $txHash = $transaction; 136 | }); 137 | 138 | $transaction = confirmTx($eth, $txHash); 139 | if (!$transaction) { 140 | throw new Error('Transaction was not confirmed.'); 141 | } 142 | 143 | echo "Transaction was confirmed" . PHP_EOL; 144 | -------------------------------------------------------------------------------- /tx.php: -------------------------------------------------------------------------------- 1 | '0x' . $nonce->toHex(), 20 | 'to' => $mainAccount, 21 | 'gas' => '0xfd240', 22 | 'gasPrice' => '0x' . Utils::toWei('5', 'gwei')->toHex(), 23 | 'value' => '0x' . $value->toHex(), 24 | 'chainId' => $chainId 25 | ]); 26 | $transaction->sign($testPrivateKey); 27 | $txHash = ''; 28 | $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $mainAccount, $ownAccount, &$txHash) { 29 | if ($err !== null) { 30 | echo 'Error: ' . $err->getMessage(); 31 | return; 32 | } 33 | echo 'Tx hash: ' . $transaction . PHP_EOL; 34 | $txHash = $transaction; 35 | }); 36 | $transaction = confirmTx($eth, $txHash); 37 | if (!$transaction) { 38 | throw new Error('Transaction was not confirmed.'); 39 | } 40 | echo "Transaction has been confirmed. " . " transaction hash: " . $txHash . " block number: " . $transaction->blockNumber . PHP_EOL; 41 | 42 | // BSC didn't support EIP1559 yet 43 | // $nonce = $nonce->add(Utils::toBn(1)); 44 | // $value = Utils::toWei('0.01', 'ether'); 45 | // $transaction = new EIP1559Transaction([ 46 | // 'nonce' => '0x' . $nonce->toHex(), 47 | // 'to' => $mainAccount, 48 | // 'gas' => '0xfd240', 49 | // 'gasPrice' => '0x' . Utils::toWei('5', 'gwei')->toHex(), 50 | // 'value' => '0x' . $value->toHex(), 51 | // 'chainId' => $chainId, 52 | // 'maxPriorityFeePerGas' => '0x1', 53 | // 'maxFeePerGas' => Utils::toWei('5', 'gwei')->toHex(), 54 | // ]); 55 | // $transaction->sign($testPrivateKey); 56 | // $txHash = ''; 57 | // $eth->sendRawTransaction('0x' . $transaction->serialize(), function ($err, $transaction) use ($eth, $mainAccount, $ownAccount, &$txHash) { 58 | // if ($err !== null) { 59 | // echo 'Error: ' . $err->getMessage(); 60 | // return; 61 | // } 62 | // echo 'Tx hash: ' . $transaction . PHP_EOL; 63 | // $txHash = $transaction; 64 | // }); 65 | // $transaction = confirmTx($eth, $txHash); 66 | // if (!$transaction) { 67 | // throw new Error('Transaction was not confirmed.'); 68 | // } 69 | // echo "Transaction has been confirmed. " . " transaction hash: " . $txHash . " block number: " . $transaction->blockNumber . PHP_EOL; -------------------------------------------------------------------------------- /utils.php: -------------------------------------------------------------------------------- 1 | getBalance($account, function ($err, $rawBalance) use (&$balance) { 6 | if ($err !== null) { 7 | throw $err; 8 | } 9 | $balance = $rawBalance; 10 | }); 11 | return $balance; 12 | } 13 | 14 | function getNonce($eth, $account) { 15 | $nonce = 0; 16 | $eth->getTransactionCount($account, function ($err, $count) use (&$nonce) { 17 | if ($err !== null) { 18 | throw $err; 19 | } 20 | $nonce = $count; 21 | }); 22 | return $nonce; 23 | } 24 | 25 | function getTransactionReceipt($eth, $txHash) { 26 | $tx; 27 | $eth->getTransactionReceipt($txHash, function ($err, $transaction) use (&$tx) { 28 | if ($err !== null) { 29 | throw $err; 30 | } 31 | $tx = $transaction; 32 | }); 33 | return $tx; 34 | } 35 | 36 | function getChainId($net) { 37 | $version; 38 | $net->version(function ($err, $ver) use (&$version) { 39 | if ($err !== null) { 40 | throw $err; 41 | } 42 | $version = $ver; 43 | }); 44 | return $version; 45 | } 46 | 47 | function confirmTx($eth, $txHash) { 48 | $transaction = null; 49 | while (!$transaction) { 50 | $transaction = getTransactionReceipt($eth, $txHash); 51 | if ($transaction) { 52 | return $transaction; 53 | } else { 54 | echo "Sleep one second and wait transaction to be confirmed" . PHP_EOL; 55 | sleep(1); 56 | } 57 | } 58 | } 59 | 60 | // getUniV2AmountsOut 61 | function getUniV2AmountsOut ($contract, $amountIn, $path, $txOptions) { 62 | $amountOut = null; 63 | $contract->call('getAmountsOut', $amountIn, $path, $txOptions, function ($err, $result) use ($path, &$amountOut) { 64 | if ($err !== null) { 65 | throw $err; 66 | } 67 | if ($result && isset($result['amounts']) && count($result['amounts']) == count($path)) { 68 | $amountOut = $result['amounts']; 69 | } else { 70 | throw new Error('failed to call getAmountsOut'); 71 | } 72 | }); 73 | return $amountOut; 74 | } --------------------------------------------------------------------------------