Blockchain Oracles: Unlocking Off-chain Data with Calimero
September 6, 2023
In the world of blockchain, efficient data management and easy access are like the bread and butter for decentralized applications to really shine. This is why we are going to talk about oracles and why this feature is important when working with private shards.
The Significance of Blockchain Oracles
Okay, first things first, What are oracles? Oracles are bridges that link the world of blockchain (the on-chain part) with the real world (the off-chain part). Why is this so cool? Well, it lets smart contracts gets data from external sources, using APIs, and responding to real-world events. In simpler terms, oracles enables blockchain applications by giving them access to real-world data. With oracles, developers can create apps that are more dynamic, real-time, and just all-around awesome.
What is Key Value Oracle
Key-value oracle typically refers to a mechanism or service that allows smart contracts or decentralized applications (DApps) to interact with external data sources using key-value pairs. Calimero private shard operates within a permissioned or consortium blockchain network, a key-value oracle operates as a bridge between the private shard and external data sources. With the use of key-value oracles in Calimero private shard, decentralised applications can benefit from the security and privacy features of private shards while still having access to external data sources when needed. This synergy ensures that sensitive data is protected and that blockchain applications can operate effectively and securely in contexts where real-world data is essential.
Benefits of the Key Value Oracle
When key-value oracles is used within private shards they offer several combined benefits that enhance the overall functionality, security, and privacy of blockchain-based applications. Here are the benefits of using key-value oracles within Calimero private shard:
Enhanced Privacy and Security: By using private shards to store sensitive data and key-value oracles to access external data, blockchain applications can maintain a high level of privacy and security for both internal and external data.
Data Integrity and Validation: By combining Calimero private shards and key-value oracles ensures that data accessed from external sources is trustworthy and that it hasn't been tampered with before being used in smart contracts.
Flexible Access to External Data: By combining private shards with key-value oracles, blockchain applications can securely access and integrate external data into their smart contracts while maintaining control over internal data.
Real-World Integration: Blockchain applications can seamlessly integrate external data into their operations while operating in a secure, private, and efficient manner.
Installing Key Value Oracles Within your Private Shard
To get started with KV Oracle within your Calimero shard, follow these steps:
2. Navigate to the Marketplace section, where you can explore and access various Calimero applications and tools.
3. Select Key Value Oracle from the available options
4. Click on the install button to initiate the installation process.
5. Once installed, access the Oracle section within the Calimero Console. Here, you will find the deployed KV Oracle ready to be used.
Updating Contract Values
Now that you've got the KV Oracle on board, it's time to start storing and updating those key-value pairs in your contract. This process involves sending a POST request to the provided endpoint, ensuring that data remains synchronized and accurate. Here's how to do it:
1. Go back to the Oracles section in the Calimero Console
2. Select the Oracle you installed and copy the endpoint details
3. Now, send a POST request to that endpoint to create or update your key-value pair. Here's a handy example of what that request might look like:
The KV Oracle will take care of storing or updating your data, making it all set for future use.
Accessing Oracle Data
Here's where the real magic happens. The KV Oracle isn't just for your one contract; you can easily fetch data from it for different contracts within the same shard. By leveraging the provided methods, such as the `get_value_from_kv_oracle` function, you can effortlessly retrieve specific values from the KV Oracle contract. Here's how:
1. First, make sure you import the right dependencies in your contract code. You'll need those to interact with the KV Oracle contract.
2. Now, define a method in your contract code to get a value from the KV Oracle contract. It might look something like this:
3. Call the `get_value_from_kv_oracle` method within your contract, providing the KV Oracle contract's AccountId and the key:
let kv_oracle_account_id = "kv_oracle_contract.testnet".to_string();
let key = "near_price".to_string();
let value_promise = self.get_value_from_kv_oracle(kv_oracle_account_id, key);
4. Lastly, handle that returned Promise however you need to. You can either wait for it to resolve or return it to the caller, depending on what your contract is all about.
Using the KV Oracle within your Calimero Private Shard
Using a key-value (KV) oracle within a private shard in a blockchain network can offer several advantages, especially in situations where data privacy, security, and real-world data integration are essential. This is feature is valuable for applications that require both data integration and robust data protection. So go ahead, dive into the world of the KV Oracle, and embark on an exciting journey with Calimero today. Check out our documentation for more in-depth details!