0

Question says it all. I have a contract that I've written and compiled via Remix. I've dumped the ABI and Bytecode into local files, and I'm reading them into my python application. I'm following the documentation (https://web3py.readthedocs.io/en/stable/contracts.html) and trying to instantiate like:

mycontract = w3.eth.contract(abi=ABI,bytecode=BYTECODE)

where ABI is the copy-pasted abi from Remix, and the BYTECODE is the copy-pasted bytecode from Remix.

But I get a TypeError: Could not format value {'linkReferences': {}, 'object': '6080604...

I should mention that I can instantiate the contract the the same ABI and an address that the contract has been deployed to via Remix, and then successfully monitor the contract to log events. But what I would really like to do is deploy the contract from Python, using the locally stored abi and bytecode generated by Remix.

Currently, the "bytecode" that Remix provides is in a structure like this:

{
  'linkReferences':[],
  'object': '6080604052336000806...',
  'opcodes': 'PUSH1 0x80...',
  'sourcemap': '50:1984:0:-;;;2...'
}

1 Answer 1

3

I figured out the answer to my own question. Yes, it's possible.

The contract expects only the "object" value of the "bytecode" structure provided by Remix. Currently, when you click to copy the "bytecode" from Remix, you end up with a structure that looks like this:

bytecode = {
  'linkReferences':[],
  'object': '6080604052336000806...',
  'opcodes': 'PUSH1 0x80...',
  'sourcemap': '50:1984:0:-;;;2...'
}

I was passing this whole structure as the bytecode argument, which is wrong. The contract is only expecting the "object" value.

3
  • I merged this elaboration into the original question with the edit button. Commented Apr 19, 2019 at 0:54
  • Not sure why this was downvoted -- it's not wrong.. although perhaps I didn't give enough context. I clarified my solution and adding more context. To be clear, this is a viable answer to the question and not merely an elaboration. Commented Apr 20, 2019 at 7:02
  • The original answer was an extension of the question and not a solution. This is great. Thanks for circling back to post a solution. You are allowed to accept your own answer. Commented Apr 20, 2019 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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