1

I'm trying to write a smart contract that takes INR as user input and converts it to equivalent eth ( wei ). I looked into chainlink datafeeds, but no luck there. Need advice on how to implement this. Thanks.

1 Answer 1

0

Firstly , you need to have a source from which you can get the exchange rates there are 2 ways for it :

  1. External API
  2. Data Feed services

Next , If you have the exchange rate, you can write the conversion function in Solidity.

solidity code : 
    uint256 convertedEthAmount = inrAmount * exchangeRate / 1e18;
     return convertedEthAmount * 1e18; // convert to wei

Lastly , in frontend you have to follow few steps to get these values ,

  1. Import the ABI
  2. Create web3 instance : const contract = new web3.eth.Contract(ABI, contractAddress);
  3. Call the solidity function : contract.methods.convert_Inr_to_Eth(inr_Amount).call()
1
  • Alright, will try it out. Thanks. Commented Mar 14, 2023 at 13:17

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.