[Solved] Error: Http request When I try to compile online

Hello,

I just start learning Sophia and try to compile some existing examples. So I go throught this example of CryptoHamster : https://github.com/aeternity/aepp-sophia-examples/blob/master/examples/CryptoHamster/contracts/crypto-hamsters.aes
but when I copy paste the code to online compilator I get this error:

I get the same error when I just try to create my own easy code with just 4lines.
Please any solution? and thank you.

Best Regards

Well, the compiler already told you what the problem is. The syntax for tuple types changed in Sophia version 4 and you are trying to compile the old syntax with the new compiler :man_shrugging:

The example is outdated, you have to update () to unit on lines 16 and 29…

2 Likes

@hanssv.chain , Thank you for you answer. it done

@hanssv.chain , Please two more question , 1- is there any way to create a random number for example the function keccak256 ?
2- How can I get the block number ?
Thank you so much for your support

Thanks @charingane, checkout the documentation on how to get the block number. protocol/sophia.md at master · aeternity/protocol · GitHub

For random numbers, hashes can only offer you pseudo random number generation with specified seed.

2 Likes

Yes, as @philipp.chain mentions, getting a truly random number is not possibly (except using an external part like an oracle) but a pseudo random number you can get from some seed-string like this:

function pseudo_random(seed : string) = Bytes.to_int(String.blake2b(seed))

(if you prefer keccak256/sha3 use String.sha3)

You can also use a recent block hash as the seed:

function pseudo_random() = Bytes.to_int(Crypto.blake2b(Chain.block_hash(Chain.height - 1)))
3 Likes