1

I'm trying to use convert in Vyper but get the following error:

vyper.exceptions.TypeMismatch: Expecting one of ('num_literal', 'int128', 'int256', 'bytes32', 'Bytes', 'address', 'bool', 'decimal') for argument 1 of convert

def forLoop() -> (uint256):
    x: uint256 = 0
    for i in [1, 2, 3]:
        x += convert(i, uint256)
    return x

2 Answers 2

1

Here it works just fine, using compiler version 0.2.8.

Maybe you should try adding this to the top of your contract:

# @version ^0.2.8

Maybe your function needs the decorator to specify it's visibility, such as:

@external
def forLoop() -> (uint256):
    x: uint256 = 0
    for i in [1, 2, 3]:
        x += convert(i, uint256)
    return x
0

You don't need to convert i into uint256 on version 0.2.12

Try as follows.

def forLoop() -> (uint256):
x: uint256 = 0
for i in [1, 2, 3]:
    x += i
return x

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.