|
| 1 | +import * as ethers from "ethers"; |
| 2 | + |
| 3 | +const erc20Abi = [ |
| 4 | + { |
| 5 | + "constant": true, |
| 6 | + "inputs": [], |
| 7 | + "name": "name", |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "", |
| 11 | + "type": "string" |
| 12 | + } |
| 13 | + ], |
| 14 | + "payable": false, |
| 15 | + "stateMutability": "view", |
| 16 | + "type": "function" |
| 17 | + }, |
| 18 | + { |
| 19 | + "constant": false, |
| 20 | + "inputs": [ |
| 21 | + { |
| 22 | + "name": "_spender", |
| 23 | + "type": "address" |
| 24 | + }, |
| 25 | + { |
| 26 | + "name": "_value", |
| 27 | + "type": "uint256" |
| 28 | + } |
| 29 | + ], |
| 30 | + "name": "approve", |
| 31 | + "outputs": [ |
| 32 | + { |
| 33 | + "name": "", |
| 34 | + "type": "bool" |
| 35 | + } |
| 36 | + ], |
| 37 | + "payable": false, |
| 38 | + "stateMutability": "nonpayable", |
| 39 | + "type": "function" |
| 40 | + }, |
| 41 | + { |
| 42 | + "constant": true, |
| 43 | + "inputs": [], |
| 44 | + "name": "totalSupply", |
| 45 | + "outputs": [ |
| 46 | + { |
| 47 | + "name": "", |
| 48 | + "type": "uint256" |
| 49 | + } |
| 50 | + ], |
| 51 | + "payable": false, |
| 52 | + "stateMutability": "view", |
| 53 | + "type": "function" |
| 54 | + }, |
| 55 | + { |
| 56 | + "constant": false, |
| 57 | + "inputs": [ |
| 58 | + { |
| 59 | + "name": "_from", |
| 60 | + "type": "address" |
| 61 | + }, |
| 62 | + { |
| 63 | + "name": "_to", |
| 64 | + "type": "address" |
| 65 | + }, |
| 66 | + { |
| 67 | + "name": "_value", |
| 68 | + "type": "uint256" |
| 69 | + } |
| 70 | + ], |
| 71 | + "name": "transferFrom", |
| 72 | + "outputs": [ |
| 73 | + { |
| 74 | + "name": "", |
| 75 | + "type": "bool" |
| 76 | + } |
| 77 | + ], |
| 78 | + "payable": false, |
| 79 | + "stateMutability": "nonpayable", |
| 80 | + "type": "function" |
| 81 | + }, |
| 82 | + { |
| 83 | + "constant": true, |
| 84 | + "inputs": [], |
| 85 | + "name": "decimals", |
| 86 | + "outputs": [ |
| 87 | + { |
| 88 | + "name": "", |
| 89 | + "type": "uint8" |
| 90 | + } |
| 91 | + ], |
| 92 | + "payable": false, |
| 93 | + "stateMutability": "view", |
| 94 | + "type": "function" |
| 95 | + }, |
| 96 | + { |
| 97 | + "constant": true, |
| 98 | + "inputs": [ |
| 99 | + { |
| 100 | + "name": "_owner", |
| 101 | + "type": "address" |
| 102 | + } |
| 103 | + ], |
| 104 | + "name": "balanceOf", |
| 105 | + "outputs": [ |
| 106 | + { |
| 107 | + "name": "balance", |
| 108 | + "type": "uint256" |
| 109 | + } |
| 110 | + ], |
| 111 | + "payable": false, |
| 112 | + "stateMutability": "view", |
| 113 | + "type": "function" |
| 114 | + }, |
| 115 | + { |
| 116 | + "constant": true, |
| 117 | + "inputs": [], |
| 118 | + "name": "symbol", |
| 119 | + "outputs": [ |
| 120 | + { |
| 121 | + "name": "", |
| 122 | + "type": "string" |
| 123 | + } |
| 124 | + ], |
| 125 | + "payable": false, |
| 126 | + "stateMutability": "view", |
| 127 | + "type": "function" |
| 128 | + }, |
| 129 | + { |
| 130 | + "constant": false, |
| 131 | + "inputs": [ |
| 132 | + { |
| 133 | + "name": "_to", |
| 134 | + "type": "address" |
| 135 | + }, |
| 136 | + { |
| 137 | + "name": "_value", |
| 138 | + "type": "uint256" |
| 139 | + } |
| 140 | + ], |
| 141 | + "name": "transfer", |
| 142 | + "outputs": [ |
| 143 | + { |
| 144 | + "name": "", |
| 145 | + "type": "bool" |
| 146 | + } |
| 147 | + ], |
| 148 | + "payable": false, |
| 149 | + "stateMutability": "nonpayable", |
| 150 | + "type": "function" |
| 151 | + }, |
| 152 | + { |
| 153 | + "constant": true, |
| 154 | + "inputs": [ |
| 155 | + { |
| 156 | + "name": "_owner", |
| 157 | + "type": "address" |
| 158 | + }, |
| 159 | + { |
| 160 | + "name": "_spender", |
| 161 | + "type": "address" |
| 162 | + } |
| 163 | + ], |
| 164 | + "name": "allowance", |
| 165 | + "outputs": [ |
| 166 | + { |
| 167 | + "name": "", |
| 168 | + "type": "uint256" |
| 169 | + } |
| 170 | + ], |
| 171 | + "payable": false, |
| 172 | + "stateMutability": "view", |
| 173 | + "type": "function" |
| 174 | + }, |
| 175 | + { |
| 176 | + "payable": true, |
| 177 | + "stateMutability": "payable", |
| 178 | + "type": "fallback" |
| 179 | + }, |
| 180 | + { |
| 181 | + "anonymous": false, |
| 182 | + "inputs": [ |
| 183 | + { |
| 184 | + "indexed": true, |
| 185 | + "name": "owner", |
| 186 | + "type": "address" |
| 187 | + }, |
| 188 | + { |
| 189 | + "indexed": true, |
| 190 | + "name": "spender", |
| 191 | + "type": "address" |
| 192 | + }, |
| 193 | + { |
| 194 | + "indexed": false, |
| 195 | + "name": "value", |
| 196 | + "type": "uint256" |
| 197 | + } |
| 198 | + ], |
| 199 | + "name": "Approval", |
| 200 | + "type": "event" |
| 201 | + }, |
| 202 | + { |
| 203 | + "anonymous": false, |
| 204 | + "inputs": [ |
| 205 | + { |
| 206 | + "indexed": true, |
| 207 | + "name": "from", |
| 208 | + "type": "address" |
| 209 | + }, |
| 210 | + { |
| 211 | + "indexed": true, |
| 212 | + "name": "to", |
| 213 | + "type": "address" |
| 214 | + }, |
| 215 | + { |
| 216 | + "indexed": false, |
| 217 | + "name": "value", |
| 218 | + "type": "uint256" |
| 219 | + } |
| 220 | + ], |
| 221 | + "name": "Transfer", |
| 222 | + "type": "event" |
| 223 | + } |
| 224 | +] |
| 225 | + |
| 226 | +async function main() { |
| 227 | + const provider = new ethers.JsonRpcProvider("https://sepolia-rollup.arbitrum.io/rpc"); |
| 228 | + |
| 229 | + const wallet = ethers.Wallet.fromPhrase("attract chase stool practice orphan version bargain spin crisp often chuckle auction save own exclude", provider); |
| 230 | + console.log(wallet.address); |
| 231 | + |
| 232 | + const sender = "0x1d11a5c0adf049a5ab706cbaae78d681e25bbe62"; |
| 233 | + const usdc = new ethers.Contract("0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d", erc20Abi, provider); |
| 234 | + |
| 235 | + console.log(await usdc.balanceOf(sender)); |
| 236 | + |
| 237 | + console.log(await usdc.approve.estimateGas("0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d", 100, { from: sender })) |
| 238 | + |
| 239 | + const transferTx = usdc.interface.encodeFunctionData("approve", ["0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d", 100]); |
| 240 | + |
| 241 | + console.log({ transferTx }); |
| 242 | +} |
| 243 | + |
| 244 | +main(); |
| 245 | + |
0 commit comments