Skip to content
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

Chainlink Functions Edits #1739

Merged
merged 13 commits into from
Feb 5, 2024
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
134 changes: 125 additions & 9 deletions src/content/chainlink-functions/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,151 @@ You will test on Polygon Mumbai, so you must have an Ethereum web3 wallet with e

<ClickToZoom src="/images/chainlink-functions/getting-started/deploy.jpg" />

1. After you confirm the transaction, the contract address appears in the **Deployed Contracts** list. Copy the contract address.
1. After you confirm the transaction, the contract address appears in the **Deployed Contracts** list. Copy the contract address and save it for later. You will use this address with a Functions Subscription.

<ClickToZoom src="/images/chainlink-functions/getting-started/deployed-contracts.jpg" />

### Create a subscription

Follow the [Managing Functions Subscriptions](/chainlink-functions/resources/subscriptions#create-a-subscription) guide to accept the Chainlink Functions Terms of Service (ToS), create a subscription, fund it, then add your consumer contract address to it.
You use a Chainlink Functions subscription to pay for, manage, and track Functions requests.

You can find the Chainlink Functions Subscription Manager at [functions.chain.link](https://functions.chain.link/).
1. Go to [functions.chain.link](https://functions.chain.link/).

## Run the example
1. Click **Connect wallet**:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/frontend-landing.jpg"
alt="Chainlink Functions subscription landing page"
style="max-width: 70%;"
/>

1. Read and accept the Chainlink Foundation Terms of Service. Then click **MetaMask**.

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/accept-CL-foundation-tos.jpg"
alt="Chainlink Functions accept ToS"
style="max-width: 70%;"
/>

1. Make sure your wallet is connected to the _Polygon Mumbai_ testnet. If not, click the network name in the top right corner of the page and select _Polygon Mumbai_.

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/wallet-connected-polygon-mumbai.jpg"
style="max-width: 70%;"
alt="Chainlink Functions subscription landing page"
/>

1. Click **Create Subscription**:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/frontend-landing-wallet-connected.jpg"
alt="Chainlink Functions subscription landing page"
style="max-width: 70%;"
/>

1. Provide an email address and an optional subscription name:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/create-subscription.jpg"
alt="Chainlink Functions create subscription"
style="max-width: 70%;"
/>

1. The first time you interact with the Subscription Manager using your EOA, you must accept the Terms of Service (ToS). A MetaMask popup appears and you are asked to accept the ToS:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/acceptTos.jpg"
alt="Chainlink Functions accept ToS"
style="max-width: 70%;"
/>

1. After you approve the ToS, another MetaMask popup appears, and you are asked to approve the subscription creation:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/approve-create-subscription.jpg"
alt="Chainlink Functions approve subscriptions creation"
style="max-width: 70%;"
/>

1. After the subscription is created, MetaMask prompts you to sign a message that links the subscription name and email address to your subscription:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/sign-message-tos.jpg"
alt="Chainlink Functions sign message ToS"
style="max-width: 70%;"
/>

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/sign-message-tos-metamask.jpg"
alt="Chainlink Functions sign message ToS MetaMask"
style="max-width: 70%;"
/>

The example is hardcoded to communicate with Chainlink Functions on Polygon Mumbai. Read the [Examine the code](#examine-the-code) section for a detailed description of all components.
### Fund your subscription

To run the example:
1. After the subscription is created, the Functions UI prompts you to fund your subscription. Click **Add funds**:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/subscription-created.jpg"
alt="Chainlink Functions subscription created"
style="max-width: 70%;"
/>

1. For this example, add 2 LINK and click **Add funds**:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/subscription-created-add-funds.jpg"
alt="Chainlink Functions subscription add funds"
style="max-width: 70%;"
/>

### Add a consumer to your subscription

1. After you fund your subscription, add your consumer to it. Specify the address for the consumer contract that you deployed earlier and click **Add consumer**. MetaMask prompts you to confirm the transaction.

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/subscription-created-add-consumer.jpg"
alt="Chainlink Functions subscription add consumer"
style="max-width: 70%;"
/>

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/subscription-created-add-consumer-2.jpg"
alt="Chainlink Functions subscription add consumer"
style="max-width: 70%;"
/>

1. Subscription creation and configuration is complete. You can always see the details of your subscription again at [functions.chain.link](https://functions.chain.link):

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/subscription-details-after-creation.jpg"
alt="Chainlink Functions subscription details"
style="max-width: 70%;"
/>

## Run the example

The example is hardcoded to communicate with Chainlink Functions on Polygon Mumbai. After this example is run, you can examine the code and see a detailed description of all components.

1. In Remix under the **Deploy & Run Transactions** tab, expand your contract in the **Deployed Contracts** section.
1. Expand the `sendRequest` function to display its parameters.
1. Fill in the `subscriptionId` with your subscription ID and `args` with `[1]`, then click **transact** button.
1. Fill in the `subscriptionId` with your subscription ID and `args` with `[1]`. You can find your subscription ID on the Chainlink Functions Subscription Manager at [functions.chain.link](https://functions.chain.link/). The `[1]` value for `args` specifies which argument in the response will be retrieved.

1. Click the **transact** button.

<ClickToZoom src="/images/chainlink-functions/getting-started/send-request.jpg" />

1. Wait for the request to be fulfilled. You can monitor the status of your request on the Chainlink Functions Subscription Manager.

<ClickToZoom src="/images/chainlink-functions/getting-started/request-fulfilled.jpg" />
1. Once the status is _Success_, check the character name: In Remix, under the **Deploy & Run Transactions** tab, click on the `character` function, and you'll get the name of your character.

1. Refresh the Functions UI to get the latest request status.

1. After the status is _Success_, check the character name. In Remix, under the **Deploy & Run Transactions** tab, click the `character` function. If the transaction and request ran correctly, you will see the name of your character in the response.

<ClickToZoom src="/images/chainlink-functions/getting-started/character.jpg" />

Chainlink Functions is capable of much more than just computation. Try one of the [Tutorials](/chainlink-functions/tutorials) to see examples that can GET and POST to public APIs, securely handle API secrets, handle custom responses, and query multiple APIs.
Chainlink Functions is capable of much more than just retrieving data. Try one of the [Tutorials](/chainlink-functions/tutorials) to see examples that can GET and POST to public APIs, securely handle API secrets, handle custom responses, and query multiple APIs.

## Examine the code

Expand Down
38 changes: 20 additions & 18 deletions src/content/chainlink-functions/resources/subscriptions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ Chainlink Functions is offered "as is" and "as available" without conditions or

The Chainlink Functions Subscription Manager is available [here](https://functions.chain.link/). The Functions Subscription Manager lets you create a subscription, add consumers to it, remove consumers from it, fund it with LINK, and delete it.

When you connect to the Subscription Manager, choose the correct network, then click on _connect wallet_.
When you connect to the Subscription Manager, choose the correct network, then click _connect wallet_.

## Subscriptions

You use a Chainlink Functions subscription to pay for, manage, and track Functions requests.

### Create a subscription

1. Open the landing page and click on _Create Subscription_:
1. Open [functions.chain.link](https://functions.chain.link/) and click _Create Subscription_:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/frontend-landing.jpg"
src="/images/chainlink-functions/tutorials/subscription/frontend-landing-wallet-connected.jpg"
alt="Chainlink Functions subscription landing page"
/>

1. You are asked to provide an optional email address and subscription name:
1. Provide an email address and an optional subscription name:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/create-subscription.jpg"
Expand All @@ -47,14 +49,14 @@ When you connect to the Subscription Manager, choose the correct network, then c
alt="Chainlink Functions accept ToS"
/>

1. When you approve the ToS, a Metamask popup appears, and you are asked to approve the subscription creation:
1. When you approve the ToS, a MetaMask popup appears that asks you to approve the subscription creation:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/approve-create-subscription.jpg"
alt="Chainlink Functions approve subscriptions creation"
/>

1. Once the subscription is created, you are asked to sign a message in MetaMask to link the subscription name and email address to your subscription:
1. After the subscription is created, you are asked to sign a message in MetaMask to link the subscription name and email address to your subscription:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/sign-message-tos.jpg"
Expand All @@ -65,10 +67,10 @@ When you connect to the Subscription Manager, choose the correct network, then c

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/sign-message-tos-metamask.jpg"
alt="Chainlink Functions sign message ToS Metamask"
alt="Chainlink Functions sign message ToS MetaMask"
/>

1. After the subscription is created, you can fund it with LINK:
1. After the subscription is created, fund it with LINK:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/subscription-created-add-funds.jpg"
Expand Down Expand Up @@ -96,7 +98,7 @@ When you connect to the Subscription Manager, choose the correct network, then c

### Fund a Subscription

1. Open your subscription details and click on _Actions_ then click on _Fund subscription_:
1. Open your subscription details and click _Actions_ then click _Fund subscription_:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-click-fund.jpg"
Expand All @@ -110,7 +112,7 @@ When you connect to the Subscription Manager, choose the correct network, then c
alt="Chainlink Functions add fund to your subscription"
/>

1. A Metamask popup appears, and you are asked to confirm the transaction. After you confirm the transaction, a confirmation screen appears:
1. A MetaMask popup appears, and you are asked to confirm the transaction. After you confirm the transaction, a confirmation screen appears:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-funded.jpg"
Expand All @@ -119,7 +121,7 @@ When you connect to the Subscription Manager, choose the correct network, then c

### Add a consumer contract to a Subscription

1. Open your subscription details and click on _Add Consumer_:
1. Open your subscription details and click _Add Consumer_:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-add-consumer.jpg"
Expand All @@ -133,7 +135,7 @@ When you connect to the Subscription Manager, choose the correct network, then c
alt="Chainlink Functions provider consumer address"
/>

1. A Metamask popup appears, and you are asked to confirm the transaction. After you confirm the transaction, a confirmation screen appears:
1. A MetaMask popup appears, and you are asked to confirm the transaction. After you confirm the transaction, a confirmation screen appears:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-consumer-added.jpg"
Expand All @@ -142,14 +144,14 @@ When you connect to the Subscription Manager, choose the correct network, then c

### Remove a consumer contract from a Subscription

1. Open your subscription details and click on the consumer you want to remove, then _Remove Consumer_:
1. Open your subscription details and click the consumer you want to remove, then _Remove Consumer_:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-remove-consumer.jpg"
alt="Chainlink Functions remove consumer"
/>

1. A Metamask popup appears, and you are asked to confirm the transaction.
1. A MetaMask popup appears, and you are asked to confirm the transaction.

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-remove-consumer-confirm.jpg"
Expand All @@ -158,7 +160,7 @@ When you connect to the Subscription Manager, choose the correct network, then c

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-remove-consumer-confirm2.jpg"
alt="Chainlink Functions confirm the removal of the consumer in Metamask"
alt="Chainlink Functions confirm the removal of the consumer in MetaMask"
/>

1. After you confirm the transaction, a confirmation screen appears:
Expand All @@ -172,7 +174,7 @@ When you connect to the Subscription Manager, choose the correct network, then c

**Note**: You cannot cancel a subscription if there are in-flight requests. In-flight requests are requests that still need to be fulfilled.

1. Open your subscription details, click on _Actions_, then _Cancel subscription_:
1. Open your subscription details, click _Actions_, then _Cancel subscription_:

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-cancel.jpg"
Expand All @@ -186,7 +188,7 @@ When you connect to the Subscription Manager, choose the correct network, then c
alt="Chainlink Functions cancel subscription"
/>

1. A Metamask popup appears, and you are asked to confirm the transaction.
1. A MetaMask popup appears, and you are asked to confirm the transaction.

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-cancel-confirm.jpg"
Expand All @@ -195,7 +197,7 @@ When you connect to the Subscription Manager, choose the correct network, then c

<ClickToZoom
src="/images/chainlink-functions/tutorials/subscription/your-subscription-cancel-confirm2.jpg"
alt="Chainlink Functions confirm the removal of the subscription in Metamask"
alt="Chainlink Functions confirm the removal of the subscription in MetaMask"
/>

1. After you confirm the transaction, a confirmation screen appears:
Expand Down
Loading