Easy Guide to Converting USD price to crypto in Smart Contracts
Read summaryIn this 9-minute video, Arthur explains how to exchange US dollars to cryptocurrency in a Solidity smart contract. He demonstrates this using the Matic cryptocurrency as an example. Arthur mentions that smart contracts cannot fetch information directly from external sources like CoinGecko, so he uses oracles as intermediaries. He uses a test oracle deployed on the Mumbai test network to fetch the current exchange rate between dollars and Matic.
To align the values returned by the oracle with the Ethereum ecosystem's denomination, Arthur multiplies the current fiat price by 10 to the power of 10. He then calculates the Matic price by dividing the fiat price multiplied by 10^18 by the current fiat price. Finally, he returns the price in Matic.
Arthur encounters an error but quickly corrects it. He deploys the smart contract and calculates the Matic price using the given cents value. Overall, the video provides a tutorial on exchanging US dollars to cryptocurrency in a Solidity smart contract using oracles.
Hide summary