1

I'm trying to read data from Smart Contract B on Blockchain B using Smart Contract A on Blockchain A. For example, Smart Contract B has a function getPlayerAddressesAndBalance that returns data like [[player1, 50]]. I want to access this data from Smart Contract A on Blockchain A.

I understand this isn't typically possible, but I thought it might be achievable using oracles like Chainlink. However, after reviewing the Chainlink documentation, I didn't find a clear solution. Did I miss something in the Chainlink docs, or are there other oracles that support this functionality?

I looked into Chainlink CCIP, but it doesn't quite fit my needs. I'm looking for a solution to make a read and get the result.

Additionally, if this is possible with Chainlink, what would the cost per call be?

Details:

I need a mechanism to resolve disputes. The workflow would be:

  • User_A calls a function on the smart contract on Chain_A, let's say setUsername.
  • User_B calls the contract on Chain_B, providing the username that User_A setted with the previous call.
  • User_A has 1 minute to inform the Smart Contract on Chain_B if the username provided by User_B is incorrect.
  • If a dispute arises, I want to read the actual username from Chain A through an oracle or some other means.

I only want to perform this read operation when necessary, to avoid unnecessary service fees, as disputes will be infrequent. Therefore, it's not practical for me to always call the Smart Contract on Chain_B through CCIP whenever a user interacts with setUsername on Chain_A.

0

3 Answers 3

1

If you require that

User_A has 1 minute to inform the Smart Contract on Chain_B if the username provided by User_B is incorrect.

I don't think CCIP is the right tool for you, because any message sent by CCIP has to be triggered and CCIP has to wait for the transaction finalized. The whole process takes about 5-20 mins depending on the chain you are using.

CCIP(or any other cross-chain infra) is designed to send a message from the source chain to the destination chain rather than "read" something from another chain.

What I am suggesting is that you send a cross-chain message from Chain_A when a new username is set to inform C to sync up the new name with Chain_B. IMO, CCIP can be of best use in the mechanism.

If you want to read a variable from a blockchain, you can use Chainlink Functions to read from an API and then feed back the result in a decentralized manner. The Functions is designed to read data and write back to the smart contract.

1
  • Thanks, i agree, i'll check chainlink functions soon :)
    – Mat.C
    Commented Jul 30 at 8:54
1

If you want to read some value from one contract (say on chain A), and write the same value to another contract (say on chain B), then Chainlink CCIP would be quite suitable for that use-case, especially in terms of a fully on-chain, thereby transparent and decentralized solution.

If you can share some insights in terms of your contracts' minimal code and functionality, then I can add the targeted CCIP functionalities into that. Then, you can possibly extend it further for the complete use-case of your application.

Otherwise, if you are ready to add some off-chain Web2-based script in JS or Python, then it's also possible to read some value from one contract (say on chain A) using some library like ethers.js, web3.js or web3.py, and write the same to another contract (say on chain B), provided that your script is hosted live and it remains actively serving for those read/write operations. Also, it would be a compromise to the decentrality and transparency of your application, as the script would be in full-control of yours and users won't be aware of what's going on in the hosted script under the hood.

Edit: As per the additional details you've provided, if you're quite time-restricted in terms of informing the other chain about the dispute occurred on one chain, then as @Frank Kong has mentioned, you can avoid using CCIP for that particular use-case, instead you can opt for Chainlink Functions, by wrapping up your Web2-based script (as I suggested above) in the form of API, and then consume that API (to query the status of the dispute) via Chainlink Functions integrated in the corresponding smart contracts on both the chains.

But, as I mentioned, if you want to write the data (along with read) across-chain and want them to be sync in a way, that for a particular dApp (available across two chains A and B), a user registers using his username on chain A, then the registration of the same user should happen on chain B, so as to avoid any other user to claim the same username on chain B. Then, in that case of inter-chain communication, which is not that much time-restricted, then CCIP would be the optimal solution.

2
  • Thanks i provided a bit more context on the question
    – Mat.C
    Commented Jul 28 at 12:15
  • @Mat.C, I've edited my answer to add more details. Please check. Commented Jul 31 at 4:48
1

Tellor can do this! ...provided its an EVM chain. There is a query type called EVMcall that enables users to incentivize a permissionless network of reporters to read the calldata from contracts on one EVM chain and write them to another. You just specify what contract you want to call, what chain its on, and the call data you want returned to your "chain A".

More detail here: https://tellor.io/blog/tellor-evmcall-contract-calldata-across-evm-chains/

For more background on using Tellor and how to get support: https://docs.tellor.io/tellor/getting-data/introduction

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.