-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnChainMessageSender.py
More file actions
35 lines (25 loc) · 1.1 KB
/
OnChainMessageSender.py
File metadata and controls
35 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
################## Fill in with your details ##########################
walletAddress = "Your wallet address to send message from"
walletPrivateKey = "Your wallet private key"
whereToSend = "Wallet address to send message to (can be your own wallet address)"
messageToSend = "This is an example message to send. Testing testing 123."
sendValue = 0
# Setup as default for BSC mainnet
ethNodeURL = "https://bsc-dataseed.binance.org"
gasPrice = 5
#######################################################################
from web3 import Web3
web3 = Web3(Web3.HTTPProvider(ethNodeURL))
rawTX = {
'from': walletAddress,
'to': whereToSend,
'value': web3.toWei(sendValue, 'ether'),
'data': messageToSend.encode("utf-8").hex(),
'gasPrice': web3.toWei(gasPrice, 'gwei'),
'nonce': web3.eth.get_transaction_count(walletAddress),
'chainId': web3.eth.chain_id
}
rawTX['gas'] = web3.eth.estimateGas(rawTX)
signedTX = web3.eth.account.sign_transaction(rawTX, walletPrivateKey)
txHash = web3.eth.send_raw_transaction(signedTX.rawTransaction)
print("Successfully sent message TX: " + web3.toHex(txHash))