I have a contract with this abi

    "stateMutability": "nonpayable",
    "type": "constructor",
    "inputs": [
        {"name": "longitude", "type": "fixed168x10"},
        {"name": "latitude", "type": "fixed168x10"}
    "outputs": [],
    "gas": 105370

When I tried to create the transaction to make contract like this

contract = w3.eth.contract(bytecode=bytecode, abi=abi)

latitude = 0.0
longitude = 0.0
constructor = contract.constructor(latitude=latitude, longitude=longitude)

this error showed up

TypeError: One or more arguments could not be encoded to the necessary ABI type.  Expected types are: fixed168x10, fixed168x10

I tried to change the longitude and latitude type to

from decimal import Decimal

latitude = Decimal(0.0)
longitude = Decimal(0.0)
constructor = contract.constructor(latitude=latitude, longitude=longitude)

But the error keep showed up. How can I put decimal parameter to contract function?

Edit: I made the contract using vyper and clearly in vyper documentation state there is type decimal here


Solidity does not have floating points or decimals. Thus, all numbers need to be converted to fixed point math.

Here the relevant Solidity documentation.

The 168x10 means that that there are 168 bits for the whole part of the number and 10 decimal points for the fractions.

Thus, you need to shift your number 10 decimal left.

fixed_point = int(value * (10**10))

  • Why is it become integer and not floating point number? Jun 22 at 8:53
  • Solidity does not have floating points or decimals. Please let me know if there is something if you do not understand about this part. Jun 22 at 10:29
  • 1
    I'm using vyper and there is decimal type data in vyper. Why should I put integer then? Jun 23 at 5:49
  • I suggest you study the Vyper documentation, as it explains the correct number of decimals: vyper.readthedocs.io/en/stable/types.html#decimals Jun 23 at 7:37

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.