Im trying to publish contracts with libraries in them and im getting the below issue. Contracts without libraries publish just fine. Can someone who might have faced this issue before advise what the tweak required to the code is ?
import json
import web3
from web3 import Web3, HTTPProvider
from solc import compile_source
from web3.contract import ConciseContract
with open('BurnableCrowdsaleToken_Flat_v2.sol', 'r') as myfile:
contract_source_code = myfile.read()
compiled_sol = compile_source(contract_source_code)
contract_interface = compiled_sol['<stdin>:BurnableCrowdsaleToken']
web3 = Web3(HTTPProvider('http://localhost:8545'))
from web3.middleware import geth_poa_middleware
web3.middleware_stack.inject(geth_poa_middleware, layer=0)
contract_ = web3.eth.contract(
abi=contract_interface['abi'],
bytecode=contract_interface['bin'])
acct = web3.eth.account.privateKeyToAccount('myprivatekey')
construct_txn = contract_.constructor("Burnable Token","BCT","50000","18","true").buildTransaction({
'from': acct.address,
'nonce': web3.eth.getTransactionCount(acct.address),
'gas': 1728712,
'gasPrice': web3.toWei('21', 'gwei')})
signed = acct.signTransaction(construct_txn)
tx_hash = web3.eth.sendRawTransaction(signed.rawTransaction)
tx_receipt = web3.eth.waitForTransactionReceipt(tx_hash)
print (tx_receipt.contractAddress)
contract solidity here
https://gist.github.com/troowala/2860203ffb2cad3d38cd3c0301423a28
Error below
$ python3 contracts_priv.py
Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/web3/utils/formatters.py", line 68, in apply_formatters_to_dict
yield key, formatters[key](item) File "/usr/local/lib/python3.5/dist-packages/web3/utils/normalizers.py", line 166, in normalize_bytecode
bytecode = HexBytes(bytecode) File "/usr/local/lib/python3.5/dist-packages/hexbytes/main.py", line 17, in
__new__
bytesval = hexstr_if_str(to_bytes, val) File "/usr/local/lib/python3.5/dist-packages/eth_utils/conversions.py", line 146, in hexstr_if_str
hexstr_or_primitive, ValueError: when sending a str, it must be a hex string.
Got: '6060604052.....be907dd5250029'
Traceback (most recent call last): File "contracts_priv.py", line 28, in <module>
bytecode=contract_interface['bin']) File "/usr/local/lib/python3.5/dist-packages/web3/eth.py", line 367, in contract
ContractFactory = ContractFactoryClass.factory(self.web3, **kwargs) File "/usr/local/lib/python3.5/dist-packages/web3/contract.py", line 265, in factory
normalizers=normalizers) File "/usr/local/lib/python3.5/dist-packages/web3/utils/datatypes.py", line 33, in __new__
namespace) File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__ File "/usr/local/lib/python3.5/dist-packages/eth_utils/functional.py", line 22, in inner
return callback(fn(*args, **kwargs)) File "/usr/local/lib/python3.5/dist-packages/web3/utils/formatters.py", line 70, in apply_formatters_to_dict
raise type(exc)("Could not format value %r as field %r" % (item, key)) from exc ValueError: Could not format value '6060604052600....907dd5250029' as field 'bytecode'