Approximating cost of using Chainlink for custom API - ethereum

I am planning out a new project in which I need to connect one particular Fiat payment gateway to my smart contract. I don't want to have a system with a centralized backend, so I am exploring the possibility to use Chainlink to communicate with API and then pass response to my smart contract. I know that Chainlink allows any contract to access any external data source through their decentralized oracle network. The problem is I can't approximate how much LINK it will cost me to get a response from 1 oracle. Is there some average cost of a 1 response from an oracle and what determines such cost
I tried to look up this information, but it does not seem that this topic is discussed much. Also probably I didn't look in the right place

The problem is I can't approximate how much LINK it will cost me to
get response from 1 oracle.
Nobody can. When you make a request to oracle, you are calling a smart contract function and this will cost you gas which varies depending on the congestion in the system. if system is busy, it will cost more gas. Also when you interact with the chainlink, you are actually passing data to chainlink smart contract which makes some calculations, so you pay for those gas too.
Calling one oracle is sending a request to one oracle. oracle is a chainlink node operator, and it set its own price. But sending a request to only one node is not a decentralized approach even though each node have multiple data resources. you should make a request to several nodes meaning that you need to pay each node operator. when you make a request to several nodes, you receive the average of those responses.

The service you want to use is Chainlink Any Api, and in the service the cost of LINK depends on the node operator you are using.
There is a fee required by node operator. When you send a request, you actually require Chainlink node to provide a service. Usually the service is not free and the fee of a request is set by the node operator. The fee varies across different node operators. If you are only a consumer to use service provided by node operators, you just need to check the fee of different node operators.
you, of course, also has to pay gas fee for your transaction, but that it it costed in ETH rather than LINK (as you asking how much LINK it will cost, I assume you know it).
If you are a node operator and want to run the service for yourself, you may want to consider the following 2 factors:
Congestion of the system mentioned by #Yilmaz. When the blockchain you are using is very busy, the gas price is high so that the more gas fee, which is the result of (gas price) x(gas limit), will be cost more.
The logic of fulfill function in your contract. Fulfillment function is the "callback" function of Chainlink Any Api. Oracle node will fetch the data demand in the request and then call the fulfill function in consumer contract. In fulfill function, logics varies from simply saving the data in a variable or doing some calculations. The more complex logics, the more gas limit required.
Hope it helps!

Related

Why is smart contract interact with smart contract necessary?

I'm new in blockchain development, I wonder why is it necessary to interact with contract from another contract instead of from a personal EOA address?
Besides the delegatecall, I can't imaging any advantage to use contract to call another deployed contract's functions. As a user, I may rather use ethers or web3js through wallet etc to interact with a deployed smart contract instead.
would you please show me some reasons or necessary cases that I should design my project using a smart contract to interact with another smart contract? Thanks a lot!
There are too many use cases:
1- Upgradeable contracts or proxy contracts. Since blockchain technology is evolving so fast, it is so hard to write a contract that will be scalable. With proxy contracts, user calls the proxy contract but proxy calls the main contract. if in the future you have to change the logic of the contract, you deploy a new contract and make the proxy contract call this new contract. This way users will not get affected. You can read more about this pattern here
2- If you ever need to get data from real world, you cannot make an api call because this is not safe and not deterministic. for this reason, we use oracle services which also calls to many other smart contracts behind the scene, gets the results from each, and make a final response to the user. You can read more about oracles here
3- another use case is factory contracts. think about it as a class and users keep make an instance of it. that way instead of factory owner pays for the new contract creation, user will be paying for the deployment. you can read more about factory contracts
4- defi platforms have too many smart contracts and they are interacting each other. They keep the logic separate from each other, so they maintain better and see the missing points better. also putting everything in one contract would make contract code is bloated and make a mess. you can read uniswap
5- another use case to deploy library smart contracts. those are usually mathematical contracts which are deployed once and once u need complex functionalities, instead of you implement in your contract, you use library contracts and use them in your project. You can read about libraries
6- another use case is solving the scalability issues. imagine you have one kitchen and you have to serve all the customers from only one kitchen. As you get more customers, your service will eventually halted. so, there are layer 2 solutions to transfer some of the orders to different kitchens. and this of course happen through smart contract communications. more on layer 2
7- In general you can use inheritance. You deploy some contracts and inherit the logic from those smart contract. that is why you see openzeppelin contracts always inherit from each other
For example there are some standarts in Ethereum ecosystem. ERC20, ERC721, ERC1155 and others. So when you developing new project, instead of writing it from scratch you could install openzeppelin-contracts, import them and inherit. Afterwards you have this "carcass", on the top of which you can implement some additional functionality/custome code, etc. That approach is way more convenient and secure.
Another great example chainlink-contracts. Via them you can read from oracles. Oracles are smart contracts that keep track of cryptocurrencies prices online. Say you want your users to pay 10$ to participate in lottery/some giveaway. Your contract interacts with chainlink contract and makes sure that amount of eth that user paid is greater or equal to 10$ otherwise it returns error.
In solidity there is no true randomness, but again throughout interacting with chainlink contracts we can reach it. Another chainlink feature is automation contracts, check chainlink documentation to learn more(https://docs.chain.link/). To sum up id say that there is a lot of different protocoles/concepts which easier to interact with than to write it again.
"No need to reinvent the wheel"

BSC or Ethereum transaction history

I am thinking of one thing for the transaction history data. Whether there is an API call, maybe RPC call or REST call, that we can query target wallet address transaction history? I am trying for making a wallet, I think if we can show users their transaction history, it is a good feature for the user experience.
For this question, there are maybe some ways:
Call Bcsscan or Ethereumscan API, directly.
Start your own server, subscribe to all events, and store them to DB and query events in DB.
Any other good ideas for this feature.
For method 2) Currently to extract the full address interaction history you need to walk through all blockchain blocks and then all transactions in those using EVM tracing.
For method 1) You can also get some details over Etherscan API, but please note that this is not an open-source product and you need to contact their paid product support to understand what data is available over their API and what are the API limitations.

Does oracle make ethereum smart contract nondeterministic? If so how can one replay internal transactions deterministically?

I have a newbie question. As I understand, ethereum internal transactions are not stored on-chain. One can replay them when replaying the blocks. This seems to assume that smart contracts' behavior is deterministic. What if there are oracles? Does that make the smart contract's behavior nondeterministic and therefore one can't always replay the same internal transactions?
A blockchain oracle is any device or entity that connects a deterministic blockchain with off-chain data. The way they work is these oracles actually enter data on the blockchain through an external transaction. this way we can guarantee that the blockchain has all the information needs to verify itself. So instead of calling an API, an off-chain oracle will actually get the API and then report it on chain in a transaction. that way there is no API calling in the ethereum. Oracles are known as blockchain middlewares as they bridge the blockchain world to the real world.
Oracles are trusted entities because they are capable of digitally signing or digitally attesting the data to prove that the data is authentic. This proof is called proof of validity or proof of authenticity.
Oracles should not be able to manipulate the data they provide and must be able to provide factual data. Even though oracles
are trusted, it may still be possible that,
in some cases, the data is incorrect due to manipulation or a fault in the system. Therefore, oracles must not be able to modify the data. This validation can be provided by using various cryptographic proofing schemes. Some mechanisms to produce proof of data security:
TLSNotary
Android proof
Ledger proof
Trusted hardware-assisted proofs
DEcentralized Oracles:
As blockchain platforms such are fully decentralized, it is expected that oracle services should also be decentralized. This type of oracle can be built based on a distributed mechanism. For more You can read here:
https://medium.com/stakin/the-top-decentralized-oracles-169b94dfbb83

Pay a user's gas: Ethereum

I need some assistance. I am working on a smart contract that will allow a user to save a string (mapping(address=>string)). The only problem, I would like the contract to pay for the gas for the user to save the string. Any idea on how to
This is a proposed feature but not yet implemented: https://github.com/ethereum/EIPs/issues/1776
This feature is known as meta-transaction: the sender of the transaction doesn't pay for gas.
While there is no native way to conduct meta-transactions yet, there are third-party efforts to implement it, searching the web with meta-transaction keyword should yield useful stuff.
Have a look at the Gas Station Network Alliance:
https://blog.zeppelinos.org/gas-station-network-alliance/
Depending on your use case, if you don't need to save strings directly on chain, an alternative would be something like Peepeth - microblogging with a soul. Peepeth batches signed messages stored in IPFS and anchors the batched data on chain: https://peepeth.com/a/free

Can we get transaction information recorded in the past block using Solidity in the Smart contract?

I am studying blockchain with Ethereum, and I want to use past transaction data in the Smart contract using Solidity.
If I use Web3.js module in the program written in javascript, I can get these data easily.
But I can't get these data in the Smart contract using Solidity.
Reference of Solidity says that we can get current block number, blockhash, etc., by using "block.number" and "block.blockhash(uint blockNumber)" functions, but doesn't mention getting transaction data.
(http://solidity.readthedocs.io/en/latest/units-and-global-variables.html#special-variables-and-functions)
please help me.
The answer is simple. Unfortunately, you simply can’t access old transaction or block data onchain from Solidity. At most, you can access hashes of last 256 blocks (see blockhash in documentation )
Alternatively, as a workaround you could consider using Oraclize. Oraclize represents way to read offchain data onchain, so you could try to read transaction data from Etherscan web API. The way Oraclize works is that :
You request to Oraclize smart contract what data you want to fetch from internet (some URL)
Oraclize offchain servers then detect your on-chain request
The look up the data you wanted (they'll make some http request to the URL you provided)
Once they get response, they will send transaction to your contract (calling specific callback method) containing data you requested
With such approach however, you are relying that:
EtherScan is up and running
Oraclize is up un running.
If you only care about transaction data related to your smart contracts, another way would be to store that transaction data onchain. Maybe we could gave you some more suggestions if you tell us more about what specific problem are you solving.