Last active
May 30, 2019 13:38
-
-
Save ppillip/47223d8dfe5c4aae73c980215c0c3701 to your computer and use it in GitHub Desktop.
클레이보내기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {ethers} from "ethers"; | |
| abi = [ | |
| { | |
| "constant": true, | |
| "inputs": [ | |
| { | |
| "name": "", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "adminGroup", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "address" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "name": "_toAddCreator", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "addCreator", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "name": "_sigStockOwner", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "changeSigStockOwnership", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "name": "_admin", | |
| "type": "address" | |
| }, | |
| { | |
| "name": "_num", | |
| "type": "uint8" | |
| } | |
| ], | |
| "name": "deleteSigStockAdmin", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "name": "_title", | |
| "type": "string" | |
| }, | |
| { | |
| "name": "_description", | |
| "type": "string" | |
| }, | |
| { | |
| "name": "_creatorRate", | |
| "type": "uint256" | |
| }, | |
| { | |
| "name": "_maxDivideValue", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "createProduct", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "address" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [ | |
| { | |
| "name": "", | |
| "type": "address" | |
| }, | |
| { | |
| "name": "", | |
| "type": "uint256" | |
| } | |
| ], | |
| "name": "creatorProducts", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "address" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [], | |
| "name": "SIGSTOCK_OWNER", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "address" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "name": "_productAddress", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "addCustomProduct", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "name": "_admin", | |
| "type": "address" | |
| }, | |
| { | |
| "name": "_num", | |
| "type": "uint8" | |
| } | |
| ], | |
| "name": "addSigStockAdmin", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": false, | |
| "inputs": [ | |
| { | |
| "name": "_toDeleteCreator", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "deleteCreator", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "nonpayable", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [ | |
| { | |
| "name": "_creator", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "getNumCreatorProduct", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "uint256" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [ | |
| { | |
| "name": "", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "isCreator", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "constant": true, | |
| "inputs": [ | |
| { | |
| "name": "", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "SIGSTOCK_ADMINS", | |
| "outputs": [ | |
| { | |
| "name": "", | |
| "type": "bool" | |
| } | |
| ], | |
| "payable": false, | |
| "stateMutability": "view", | |
| "type": "function" | |
| }, | |
| { | |
| "anonymous": false, | |
| "inputs": [ | |
| { | |
| "indexed": true, | |
| "name": "_from", | |
| "type": "address" | |
| }, | |
| { | |
| "indexed": true, | |
| "name": "_product", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "CreatedProduct", | |
| "type": "event" | |
| }, | |
| { | |
| "anonymous": false, | |
| "inputs": [ | |
| { | |
| "indexed": true, | |
| "name": "_from", | |
| "type": "address" | |
| }, | |
| { | |
| "indexed": true, | |
| "name": "_product", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "AddedCustomProduct", | |
| "type": "event" | |
| }, | |
| { | |
| "anonymous": false, | |
| "inputs": [ | |
| { | |
| "indexed": true, | |
| "name": "newCreator", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "AddedCreator", | |
| "type": "event" | |
| }, | |
| { | |
| "anonymous": false, | |
| "inputs": [ | |
| { | |
| "indexed": true, | |
| "name": "toDeleteCreator", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "DeletedCreator", | |
| "type": "event" | |
| }, | |
| { | |
| "anonymous": false, | |
| "inputs": [ | |
| { | |
| "indexed": true, | |
| "name": "newAdmin", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "AddedAdmin", | |
| "type": "event" | |
| }, | |
| { | |
| "anonymous": false, | |
| "inputs": [ | |
| { | |
| "indexed": true, | |
| "name": "toDeleteAdmin", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "DeletedAdmin", | |
| "type": "event" | |
| }, | |
| { | |
| "anonymous": false, | |
| "inputs": [ | |
| { | |
| "indexed": true, | |
| "name": "_newOwner", | |
| "type": "address" | |
| } | |
| ], | |
| "name": "ChangedSigStockOwner", | |
| "type": "event" | |
| } | |
| ]; | |
| contractAddress = "0x96cb79083270e968cbaca419ed7c90bf94ced8ad"; | |
| provider = new ethers.providers.JsonRpcProvider('https://api.baobab.klaytn.net:8651'); | |
| contract = new ethers.Contract(contractAddress, abi, provider); | |
| senderPK = "0x852a1093e53ab5d707adf7f5803cbdd6d27cf5e6556e91524867a2d1ee8c8cf2"; | |
| rcvAddr = "0x08be38ad4166a5312daef8dd7519c540d81ad52e"; | |
| wallet = new ethers.Wallet ( senderPK ,provider ); | |
| provider.getBalance("0x0F1dfA0C77eF7b0046a712dc0Add3329606f73c2").then(function(a){ | |
| console.log("보내는분 : ",ethers.utils.formatEther(a)); | |
| }); | |
| provider.getBalance(rcvAddr).then(function(a){ | |
| console.log("받는분 : ",ethers.utils.formatEther(a)); | |
| }); | |
| //요기서 부터 봐주세요 | |
| (async function(){ | |
| let provider = new ethers.providers.JsonRpcProvider('https://api.baobab.klaytn.net:8651'); | |
| let senderPK = "0x852a1093e53ab5d707adf7f5803cbdd6d27cf5e6556e91524867a2d1ee8c8cf2"; | |
| let rcvAddr = "0x08be38ad4166a5312daef8dd7519c540d81ad52e"; | |
| let wallet = new ethers.Wallet ( senderPK ,provider ); | |
| console.log( await wallet.getAddress() ); | |
| let balance = await wallet.getBalance(); | |
| console.log(ethers.utils.formatEther(balance)); | |
| let gasPrice = await provider.getGasPrice(); | |
| let gasLimit = 21000; | |
| //let value = balance.sub(gasPrice.mul(gasLimit)); | |
| let value = ethers.utils.parseEther('1.0'); | |
| let data = { | |
| gasLimit: gasLimit, | |
| gasPrice: gasPrice, | |
| to: rcvAddr, | |
| value: value | |
| }; | |
| let tx = await wallet.sendTransaction(data); | |
| console.log(tx); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment