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

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.

Related

Approximating cost of using Chainlink for custom API

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!

Can I sign transaction on backend using javascript on ImmutableX chain?

my question is basically written in title, but for more details, I am using node.js, I read immutableX documentation and review there SDKs, but nothing on javascript,
I want to sign the transaction in cloud function(firebase) on immutableX chain.
Main goal is to transfer ERC20 tokens from one wallet to another. In my case, token which I want to transfer is GODS.
Thanks!
Well, I've never used ImmutableX but I think that for transferring ERC20 tokens you can use any library that can interact with Ethereum contracts like web3js
https://piyopiyo.medium.com/how-to-send-erc20-token-with-web3-js-99ed040693ce

Finding relevant smart contract information in Blockchain data

First of all apologies for probably poorly named question but the fact that I can't formulate it better is probably partially a reason why I've not been successful in finding the answer. I am trying to understand where in blockchain data can I find specific value of smart contract method. For instance, as in the screen below, this specific smart contract 0xF59D66c1d593Fb10e2f8c2a6fD2C958792434B9c holds information about the totalAssets and pricePerShare. I can see the values in the Etherscan but now, having access to logs/events and transactions from Ethereum blockchain- can I find these values in either logs/events/transactions? And how would I go about finding that value per block in the past? Any hints how to approach it would be very helpful
To get historical data, you can refer to the smart contract view function indicating the block number at the time of which you want to view the result. For example, for JSON RPC, such a request looks like:
{"jsonrpc":"2.0", "method":"eth_call", "params":[{"to":"contract", "data":"function signature and parameters"}, "block number"], "id":1}") ;

Visibility of Source Code and Business Information in Ethereum blockchain

Is it correct that everyone can see my source code once smart contract code has been published to blockchain?
Is it correct that everyone can see application's businesss state and information saved in blockchain?
For example, the example below sends a request to blockchain, receives response from blockchain. In this case, can anyone see the source code and business information? The app uses Ethereum blockchain via Solidity.
https://learn.microsoft.com/en-us/azure/blockchain/service/send-transaction
Is it possible to protect source code and users can only see business states via UI? like conventional web applications.
Smart contract state and any information stored in the blockchain is visible to all observers outside of the blockchain, even local and private variables. (It is not necessarily visible to other smart contracts).
The solidity source code itself is not stored on the blockchain, only the compiled bytecode, which consist of low-level machine instructions (called opcodes) for the Ethereum Virtual Machine. Although this can't easily be converted back into your source code (i.e. all variable names will be missing), it does reveal information about what your code is doing.
In any blockchain the business info/state is visible to the participants of the blockchain network or consortium. Any smart contract state changes in done via a transaction that is shared between the participants of the transaction. Hence the contents/operations exposed via that smart contract is also visible to the participants of that transaction, so that they can verify it's validity / have a consensus on whether to accept/reject it.
To answer your question "everyone" may not be able to see the contents unless it is a public smart contract / transaction you are dealing with. in case of public transaction/contracts it is visible to that public chain. If it is a private transaction, then it is only visible to the participants of the private transaction.
Reference: Q&A

Web3JS Ethereum Contract Storage History

I have the following question, lets say a transaction calls a Smart Contract's function, which
changes the contract's state on Ethereum Mainnet. E.g. a counter variable was set from 0 to 1.
Is there an easy way to access the previous state via Web3JS?
Thanks in advance!
Yes, as long as you know where in storage to look. The JSON-RPC method eth_getStorageAt lets you retrieve storage at a given location at an arbitrary block. web3.js exposes this as web3.eth.getStorageAt().
yeah you can use events in smart contracts functions to save every interaction with the smart contract then use web3 and get all the events that happened on the smart contract like that you get all the records of the previous state .