Ethereum Api Error: Typeerror – Creating Order with incorrect argument number
As a developer who works with Ethereum -based intelligent contracts, it is not uncommon to find errors when using external APIs like Binance. In this article, we will delve into the details of an error that can occur when trying to create a binance order using the Ethereum API.
The Error: Typeerror – Create_order ()
takes 1 positional argument, but 2 were given
When you try to create a order on binance, you usually need to pass two parameters:
- The symbol of cryptocurrency (for example, ‘eth’)
- The amount of token you want to buy or sell
However, in your script, you are spending three arguments: symbol = 'eth'.
The problem
In Python 3.6 and later, when using standard argument values for function parameters, all arguments are positional. This means that if a function takes two arguments (ae
b), the second argument will be attributed to
a. To pass an extra argument, you need to use -chave word arguments.
The solution
To correct this error, you must modify your script to use Keyword Arguments instead of positional arguments forsymboland values'.
See how you can do this:
Python
Import Web3
Replace with your API credentials
Api_Key = ‘Your_api_Key’
API_SECRET = ‘your_api_secret’
Create an instance of the web3 library
Web3 = Web3.web3 (Web3 Web3 (Api_Key = Api_Key, Secret = API_SECRET)))
def Create_order (symbol: str, quantity: int) -> none:
to try:
Use the Binance API to create an order
Order = Web3.eth.Createorder (symbol = symbol, quantity = quantity)
Print (F’order created: {Order} ‘)
Except exception such as e:
Print (F’error Creating Order: {E} ‘)
Usage Example
Create_order (‘eth’, 0.1)
Replace with the desired values for ‘symbol’ and ‘quantity’
`
In this updated script, we add word arguments -chave symbol
evalue 'to the
creat_order () function.
Additional Notes
- Make sure you replaced‘your_api_key’ ‘e
' your_api_secret '' with your reais binance API credentials.
- TheWeb3.eth.createorder () function is used to create a order in the Ethereum blockchain. This method requires permission to execute a transaction; Therefore, check permissions before trying to use this function.
When using keyword arguments for ‘symbol’ and value ‘, you should now successfully create binance orders with your Ethereum-based smart contract script.