Skip to content

Instantly share code, notes, and snippets.

@hm0429
Created March 6, 2018 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hm0429/de79222f16eadb4e62577497143a05b6 to your computer and use it in GitHub Desktop.
Save hm0429/de79222f16eadb4e62577497143a05b6 to your computer and use it in GitHub Desktop.
<!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