TransWikia.com

Convert a string in scientific notation to a number

Ethereum Asked by EtherPaul on August 26, 2021

my smart contract uses an Oracle to retrieve the price. The price is returned as a string in scientific notation, for example, "3e-8". How I can convert this to number (uint)? The token has 18 decimals, so the final value in this example should be 30000000000.

One Answer

You can use the Provable's Computation Datasource, to do that https://docs.provable.xyz/#data-sources-computation.

Your use case resembles this example here https://github.com/provable-things/ethereum-examples/tree/master/solidity/computation-datasource/url-requests

Just make the relevant request to Coingecko inside a python script and then make the conversion you would expect onchain.

Please note that ARG0, ARG1, ARG2 you find inside the url-requests.py script

arg = [os.environ['ARG0'], os.environ['ARG1']]

# parse 3rd arg into kwargs if available
if 'ARG2' in os.environ: kwargs = ast.literal_eval(os.environ['ARG2'])
else: kwargs = {}

are environment variables defined at Docker level, relative to the values defined into the array given to the oraclize_query function defined inside UrlRequests.sol code.

The first element of the array specified should contain the IPFS multihash of the uploaded archive. (The value returned by IPFS add archive.zip) Then ARG0, ARG1, ... follows

Answered by Mauro on August 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP