-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SKALE Connect #22
Comments
SKALE Connect allows developers to access any external data source using the decentralized power of your SKALE Chain. If your dApp needs market data, weather temperatures, or Ethereum data, SKALE Connect provides a simple way to deliver this data to your Dapp. Hands OnHow it works
Request Formatting To make a JSON-RPC request, send an HTTP POST request with a
The response output will be a JSON object with the following fields:
Requests can be sent in batches by sending an array of JSON-RPC request objects as the data for a single POST. Example Below is shown how to make a request to the SKALE Connect. The full example, in Javascript, requests from the SKALE Calypso Testnet the balanceOf a NFT present on the Ethereum Goerli Network. require("dotenv").config();
const {
chain
} = require("./config.json");
const { ethers } = require("ethers");
const deployment = require("./smart-contracts/deployments/deployments-4.json");
const claimAbi = require("./smart-contracts/artifacts/contracts/Claim.sol/Claim.json");
const {generateOracleRequest} = require("./oracle");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
async function main() {
if (!PRIVATE_KEY) throw new Error("Private Key Not Found");
const provider = new ethers.JsonRpcProvider(chain.rpcUrl);
const signer = new ethers.Wallet(PRIVATE_KEY).connect(provider);
console.log(1);
const mainnetNFT = new ethers.Contract(deployment.mainnetNFT.address, deployment.mainnetNFT.abi);
const claim = new ethers.Contract(deployment.claim.address, claimAbi.abi, signer);
const request = {
"cid": 1,
"uri": "eth://",
"encoding": "json",
"ethApi": "eth_call",
"params": [{
"from": ethers.ZeroAddress,
"to": mainnetNFT.target,
"data": mainnetNFT.interface.encodeFunctionData(
"balanceOf",
[signer.address]
),
"gas": "0xfffff"
},
"latest"],
}
const requestStr = JSON.stringify(request);
const oracleResponse = await generateOracleRequest(requestStr.slice(1, requestStr.length - 1));
const res = oracleResponse["result"];
const paramsStartIndex = res.toString().search(/params/) + 8;
const paramsEndIndex = res.toString().search(/time/) - 2;
const parsedResult = JSON.parse(res);
const claimTransactionHash = await claim.claim([
parsedResult["cid"],
parsedResult["uri"],
parsedResult["encoding"],
parsedResult["ethApi"],
oracleResponse["result"].slice(paramsStartIndex, paramsEndIndex),
[],
[],
"",
parsedResult["time"],
parsedResult["rslts"],
parsedResult["sigs"].map((sig) => {
console.log(sig);
if (sig === null) {
return {
v: 0,
r: ethers.ZeroHash,
s: ethers.ZeroHash
}
} else {
let splitVals = sig.split(":");
return {
v: splitVals[0] == 0 ? 27 : 28,
r: ethers.zeroPadValue("0x" + (splitVals[1].length % 2 == 0 ? splitVals[1] : "0" + splitVals[1]), 32),
s: ethers.zeroPadValue("0x" + (splitVals[2].length % 2 == 0 ? splitVals[2] : "0" + splitVals[2]), 32)
}
}
})
], {
gasLimit: BigInt(140000000),
gasPrice: await provider.getFeeData().gasPrice
});
console.log("Claim Transaction Hash: ", claimTransactionHash);
const resultClaim = await claimTransactionHash.wait();
console.log("Result claim:", resultClaim);
}
main()
.catch((err) => {
process.exitCode = 1;
console.error(err);
}) TheoryOracle Methods
Supported Geth Endpoints Besides any http/https endpoint, the Oracle supports the following Geth JSON RPC endpoint for retrieving Ethereum network data:
JSON RPC API Reference oracle_submitRequest (http(s)) Submits an Oracle request and returns a message receipt. Parameters:
[NOTE]
Results: The result will be an RpcResponse JSON object with result equal to:
Example: [source]
oracle_submitRequest (eth) Submits an Oracle request to an Ethereum API and returns a message receipt. [NOTE] Parameters:
[NOTE]
Example: [source]
oracle_checkResult Checks whether an Oracle result has been derived. By default the result is signed by stem:[t+1] nodes, where stem:[t] is the maximum number of untruthful nodes. Each node signs using its ETH wallet ECDSA key. If no result has been derived, The client is supposed to wait 1 second and try again. Parameters:
Results: The result repeats JSON elements from the corresponding Oracle request, plus includes a set of additional elements:
Example: [source]
|
Suggestion for this Section
Divide example and theory since there's a lot of theory
Also, since we want to make sure the user on-boarding it's as simple as possible maybe we could have an Example Implementation section explaining step by step/script by script
The text was updated successfully, but these errors were encountered: