2

I am following tutorial entitled "DApp Development for Python Programmers" by levelup.gitconnected. The url is https://levelup.gitconnected.com/dapps-development-for-python-developers-f52b32b54f28. In this tutorial there is a python file entitled deploy.py it looks like

*deploy.py
import json
from web3 import Web3, HTTPProvider
from web3.contract import ConciseContract

# web3.py instance
w3 = Web3(HTTPProvider("https://ropsten.infura.io/v3/<API key>"))
print(w3.isConnected())

key="<Private Key here with 0x prefix>"
acct = w3.eth.account.privateKeyToAccount(key)

# compile your smart contract with truffle first
truffleFile = json.load(open('./build/contracts/greeter.json'))
abi = truffleFile['abi']
bytecode = truffleFile['bytecode']
contract= w3.eth.contract(bytecode=bytecode, abi=abi)

#building transaction
construct_txn = contract.constructor().buildTransaction({
    'from': acct.address,
    'nonce': w3.eth.getTransactionCount(acct.address),
    'gas': 1728712,
    'gasPrice': w3.toWei('21', 'gwei')})

signed = acct.signTransaction(construct_txn)

tx_hash=w3.eth.sendRawTransaction(signed.rawTransaction)
print(tx_hash.hex())
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
print("Contract Deployed At:", tx_receipt['contractAddress'])

On line 10 (key="<Private Key here with 0x prefix>") when I enter my secret key I with the 0x prefix get an error message posted below:

ValueError: The private key must be exactly 32 bytes long, instead of 34 bytes

I tried it without the 0x prefix and I get the error:

ValueError: The private key must be exactly 32 bytes long, instead of 32 bytes.

What am I missing? Thank You in advance.

5
  • There may be Spaces
    – zmy
    Aug 2 at 3:09
  • Hi BejaminHall! Welcome to Ethereum Stackexchange! Please include the code as text, it makes it easier to test.
    – Ismael
    Aug 2 at 5:54
  • Sorry about that...I change the image for text now. Aug 3 at 6:56
  • @zmy: Are you referring to "Spaces" as appearances of white space characters in my private key string? Because there are none. Aug 3 at 7:07
  • Heck, that's a weird question
    – zmy
    Aug 3 at 10:10
0

I ran into a similar issue a while back. This error most likely results from accidentally using the Infura "project secret" as the private key when you should use an ETH and LINK funded wallet private key. Make sure to get test ETH and LINK tokens into the wallet first.

0

I encountered this issue while confusing the private key with other keys and addresses. Using MetaMask, the correct private key can be found under "Account details > Export Private Key".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.