Last active
May 31, 2019 07:18
-
-
Save ppillip/6327d482017e8e817265ce0bda674763 to your computer and use it in GitHub Desktop.
에러나는 web3 코드입니다.
This file contains 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
async function sendEther(){ | |
let web3 = new Web3(new Web3.providers.WebsocketProvider('wss://ropsten.infura.io/ws')); | |
//let web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/7adb5edd47cf4c379dad4f9f3b7640ce")); | |
balance1 = await web3.eth.getBalance("0x3B598576755664a4b6f73B6f16BAc4d425715Ca9"); | |
balance2 = await web3.eth.getBalance("0xa1bBf60B7149a2fd3bb4D32B46a1c3037B4686Ea"); | |
console.log(web3.utils.fromWei(balance1)); | |
console.log(web3.utils.fromWei(balance2)); | |
let gasLimit = 21000; //await web3.eth.estimateGas({from:alice.address,to:bob.address,value:1}); | |
let gasPrice = 1000000000;//await web3.eth.getGasPrice(); | |
let value = web3.utils.toWei("0.1"); | |
let nonce = await web3.eth.getTransactionCount('0x3B598576755664a4b6f73B6f16BAc4d425715Ca9'); | |
let transaction = { | |
from:'0x3B598576755664a4b6f73B6f16BAc4d425715Ca9' | |
,to:'0xa1bBf60B7149a2fd3bb4D32B46a1c3037B4686Ea' | |
,gasPrice:gasPrice | |
,gasLimit:gasLimit | |
,value:value | |
,nonce:nonce | |
}; | |
let tx = await web3.eth.accounts.signTransaction(transaction, "70fb2482c1d3e3fa0cd4ae22e39151a1fb98d09156ba98721d105d2b57104acd"); | |
console.log("트렌젝션 서명 성공.. 다음단계 대기중",tx); | |
web3.eth.sendSignedTransaction(tx.rawTransaction.toString('hex')) | |
.once('transactionHash', (hash) => { | |
console.info('transactionHash', 'https://ropsten.etherscan.io/tx/' + hash); | |
}).once('receipt', (receipt) => { | |
console.info('receipt', receipt); | |
}).on('error', console.error); | |
}; | |
window.sendEther = sendEther; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment