Skip to content

Instantly share code, notes, and snippets.

@esell
Created February 3, 2017 07:04
Show Gist options
  • Save esell/b5c612d910a14dd3343faa71ffe77570 to your computer and use it in GitHub Desktop.
Save esell/b5c612d910a14dd3343faa71ffe77570 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var Web3 = require('web3');
var web3 = new Web3();
function getBinarySize(string) {
return Buffer.byteLength(string, 'utf8');
}
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
var fromAddress = "0xb6143608a2642b70a2c2b31f460f8511c89e3b08";
var code = "27c7650985ca463499b9e3e21bee20e7";
var hexCode = web3.toHex(code);
// how much gas?
var result = web3.eth.estimateGas({
from: fromAddress,
data: hexCode
});
console.log("estimated gas needed (ether): " + web3.fromWei(result, "ether"));
// do some work
console.log("md5 to go in: " + code);
console.log("hex of md5 to go in: " + hexCode);
web3.eth.sendTransaction({from: fromAddress, data: hexCode}, function(err, address) {
if (!err) {
//console.log(address);
var transaction = web3.eth.getTransaction(address).input;
console.log("hex of md5 from blockchain: " + transaction);
console.log("md5 from blockchain: " + web3.toAscii(transaction));
} else {
console.log(err);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment