-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chainlink Functions NPM import: mainnet support and explain _send ove…
…rride in the tutorial (#1713) * explain _send override * explain _send override * fix disclaimer * fix disclaimer * support imports on mainnet
- Loading branch information
Showing
3 changed files
with
16 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,10 +49,11 @@ This tutorial demonstrates how to import modules and use them with your Function | |
- Imported modules abide by all sandbox restrictions and do not have access to the file system, environment variables, or any other Deno permissions. | ||
|
||
<Aside type="caution"> | ||
Using module imports as part of your Functions source code is supported only on testnets at this time. Running the same code on mainnet will not succeed. | ||
|
||
Users are fully responsible for any code that they import. Chainlink Functions provides no guarantees of the validity, availability, or security of any code that a user chooses to import. For any use cases seeking to secure value, fully vet any dependencies that are being used or completely avoid importing dependencies to avoid risk from a compromised dependency or repository. | ||
|
||
Users are fully responsible for any dependencies their JavaScript source code imports. Chainlink is not responsible | ||
for any imported dependencies and provides no guarantees of the validity, availability or security of any libraries a | ||
user chooses to import or the repositories from which these dependencies are downloaded. Developers are advised to | ||
fully vet any imported dependencies or avoid dependencies altogether to avoid any risks associated with a compromised | ||
library or a compromised repository from which the dependency is downloaded. | ||
</Aside> | ||
|
||
<ChainlinkFunctions section="prerequisites-guides" /> | ||
|
@@ -135,7 +136,9 @@ The Decentralized Oracle Network will run the [JavaScript code](https://github.c | |
|
||
<ChainlinkFunctions section="deno-importe-notes" /> | ||
|
||
The example `source.js` file uses an Ethers JSON RPC call to the [`latestRoundData()` function](/data-feeds/api-reference#latestrounddata) of a [Chainlink Data Feed](/data-feeds). The request requires a few modifications to work in the Chainlink Functions environment. For example, the `JsonRpcProvider` class must be modified to handle the request asynchronously. | ||
The example `source.js` file uses a JSON RPC call to the [`latestRoundData()` function](/data-feeds/api-reference#latestrounddata) of a [Chainlink Data Feed](/data-feeds). | ||
|
||
The request requires a few modifications to work in the Chainlink Functions environment. For example, the `JsonRpcProvider` class must be inherited to override the JsonRpcProvider [`_send` method](https://docs.ethers.org/v6/api/providers/jsonrpc/#JsonRpcProvider). This customization is necessary because Deno does not natively support Node.js modules like [http](https://nodejs.org/api/http.html) or [https](https://nodejs.org/api/https.html). We override the `_send` method to use the [fetch API](https://deno.land/[email protected]?s=fetch), which is the standard way to make HTTP(s) requests in Deno. **Note**: The `url` passed in the constructor is the URL of the JSON RPC provider. | ||
|
||
```javascript | ||
// Chainlink Functions compatible Ethers JSON RPC provider class | ||
|
@@ -156,7 +159,7 @@ class FunctionsJsonRpcProvider extends ethers.JsonRpcProvider { | |
} | ||
``` | ||
|
||
After the class is extended, you can initialize the provider object and await the response. | ||
After the class is extended, you can initialize the provider object with the `RPC_URL` and await the response. | ||
|
||
```javascript | ||
const provider = new FunctionsJsonRpcProvider(RPC_URL) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a185c22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
documentation – ./
documentation-woad-five.vercel.app
docs.chain.link
documentation-git-main-chainlinklabs.vercel.app
documentation-chainlinklabs.vercel.app