任意の文字列を Ethereum ブロックチェーンに書き込むやつ
要MetaMask
code:demo.js
$(document.body).append('<h1>Write your words on Ethereum Blockchain</h1>')
$(document.body).append('<p>address: <input type="text" size="70" id="address">')
$(document.body).append('<p>your words: <input type="text" size="70" id="text">')
$(document.body).append('<p><button id="submit">submit</button></p>')
var web3js;
if (typeof web3 !== 'undefined') {
console.log("Use MetaMask")
web3js = new Web3(web3.currentProvider)
} else {
alert("Please use MetaMask")
}
$('#submit').on('click', function(event) {
let address = $('#address').val()
let text = $('#text').val()
let result = Web3.utils.isAddress(address)
if (result == true && text != "") {
let data = Web3.utils.utf8ToHex(text)
console.log(data)
web3.eth.sendTransaction({
to:address,
value:0,
gas:200000,
data: data
}, function(error, hash){
alert("Transaction Sent. " + ethscanUrl)
})
}
})