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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="./web3.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<script> | |
$(async function(){ | |
if (typeof web3 !== 'undefined') { | |
console.log("MetaMask (とか)が inject されました"); | |
web3 = new Web3(web3.currentProvider); | |
console.log("version: ", web3.version); | |
// Ether の送付元アドレス | |
// MetaMask の現在のアドレスを自動的に取得します。 | |
accounts = await web3.eth.getAccounts(); | |
fromAddress = accounts[0]; | |
// Ether の送付先アドレス | |
toAddress = "0x461CD10705dED66EF31BF652B7050b4FC919D208"; | |
// 送付する Ether の量 | |
ethvalue = 0.121; | |
// 送付する Ether の量を wei に変換します。 | |
weiValue = web3.utils.toWei(ethvalue, 'ether'); | |
// トランザクションオブジェクトを作成します。 | |
txObject = { | |
from: fromAddress, // Ether の送付元アドレス | |
to: toAddress, // Ether の送付先アドレス | |
value: weiValue, // 送付する Ether の量(単位は wei) | |
} | |
console.log(txObject); | |
// トランザクションを実行します。 | |
web3.eth.sendTransaction(txObject) | |
.on('transactionHash', function(hash){ | |
console.log("transaction hash: ", hash); | |
}) | |
.on('receipt', function(receipt){ | |
console.log("receipt: ", receipt); | |
}) | |
.on('confirmation', function(confirmationNumber, receipt){ | |
console.log("confirmationNumber: ", confirmationNumber); | |
}) | |
.on('error', console.error); | |
} else { | |
console.log("MetaMask(とか)を使用してください。"); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment