Skip to content

Instantly share code, notes, and snippets.

@janfilips
Created July 16, 2018 10:46
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 janfilips/ddfbfd6761d82c2e36a33199fdf1824e to your computer and use it in GitHub Desktop.
Save janfilips/ddfbfd6761d82c2e36a33199fdf1824e to your computer and use it in GitHub Desktop.
import os
import time
import json
import web3
from web3 import Web3, Account
from solc import compile_source
from web3.contract import ConciseContract
from eth_account.messages import defunct_hash_message
from web3.providers.rpc import HTTPProvider
# web3.py instance
w3 = Web3(HTTPProvider('https://ropsten.infura.io'))
# wallet secret
wallet_json = {"address":"60ebbf618e9b2154b9ab6809a4555a2ed1b89caf","crypto":{"cipher":"aes-128-ctr","ciphertext":"1af9a31e7f8fef2f33c7cc73715e4ad6e2a8729d59a484f9d13f1f73d99ae433","cipherparams":{"iv":"ae50be1a97ba3caeb81222c7945c40a6"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"9bcac4a59dcca583cc3ae9e7fa3f1df2a251568ed985382ceda19ece9390cba5"},"mac":"46e25a5859083a67e2804a9c95467730d5ec6fafad65a6e2dd885b35f9f3c23d"},"id":"2a412650-154b-49dc-910d-6fe6f24c1f5f","version":3}
wallet_secret = ""
wallet_key = Account.decrypt(wallet_json, wallet_secret)
account = Account.privateKeyToAccount(wallet_key)
print ('account', account)
wallet_ether_address = account.address
gas_limit = 250000
gas_price = 60
eth_amount = 3.4
#transaction = {
# "to": "0x96E0089c04c99E69E4445787bA4CC3cEA6e1B82f",
# "from": account.address,
# 'value':int(eth_amount*(10**18)),
# 'gas':gas_limit,
# 'gasPrice':int(gas_price*(10**9)),
# 'chainId':1,
# 'nonce':int(time.time())
# }
#print (transaction)
#print (account.privateKey)
#signed_transaction = w3.eth.account.signTransaction(transaction, account.privateKey)
#print ( 'signed_transaction', signed_transaction )
#transaction_id = w3.eth.sendRawTransaction(signed_transaction.rawTransaction)
#print ( 'transaction_id', transaction_id )
#print ('\nhttps://etherscan.io/tx/{0}'.format(transaction_id.hex()))
transaction = {
'to': '0x96E0089c04c99E69E4445787bA4CC3cEA6e1B82f',
'value': 1000000000,
'gas': 2000000,
'gasPrice': 234567897654321,
'nonce': 0,
'chainId': 1
}
signed = w3.eth.account.signTransaction(transaction, account.privateKey)
sent = w3.eth.sendRawTransaction(signed.rawTransaction)
print ('account.privateKey', account.privateKey)
print (sent)
#message = "hello world"
#message_hash = defunct_hash_message(text=message)
#signed_message = w3.eth.account.signHash(message_hash, private_key=account.privateKey)
#print(signed_message)
#message_hash = defunct_hash_message(text="hello world")
#verification = w3.eth.account.recoverHash(message_hash, signature=signed_message.signature)
#print(verification)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment