Skip to content

Commit

Permalink
fix functions getting-started (smartcontractkit#1623)
Browse files Browse the repository at this point in the history
* fix functions getting-started

* fix functions getting-started
  • Loading branch information
aelmanaa authored Nov 3, 2023
1 parent 83dd36e commit 8c68fab
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/content/chainlink-functions/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,15 @@ import { Aside, CopyText, CodeSample, ClickToZoom } from "@components"
import { Tabs } from "@components/Tabs"
import ChainlinkFunctions from "@features/chainlink-functions/common/ChainlinkFunctions.astro"

<Aside type="note" title="Explore Chainlink Functions Playground">
Start exploring Chainlink Functions in your browser using the [Chainlink Functions
Playground](https://functions.chain.link/playground). You can use the playground to simulate Chainlink Functions, call
APIs, and execute demo requests.
</Aside>
Learn how to make requests to the Chainlink Functions Decentralized Oracle Network (DON) and make any computation or API calls off-chain. Chainlink Functions is available on several blockchains (see the [supported networks page](/chainlink-functions/supported-networks)), but this guide uses Polygon Mumbai to simplify access to testnet funds. Complete the following tasks to get started with Chainlink Functions:

Learn how to integrate the [Chainlink Functions NPM package](https://github.com/smartcontractkit/functions-toolkit) to your own JavaScript or TypeScript project, then make requests to the Chainlink Functions Decentralized Oracle Network (DON). Chainlink Functions is available on several blockchains (see the [supported networks page](/chainlink-functions/supported-networks)), but this guide uses Polygon Mumbai to simplify access to testnet funds. Complete the following tasks to get started with Chainlink Functions:

- Set up your Web3 wallet and find your private key.
- Install the required frameworks.
- Configure your project with your environment variables.
- Simulate a Chainlink Functions request on your local machine.
- Send a Chainlink Functions request to the DON.

## Example

This guide shows you how to:

- Send a JavaScript source code from your smart contract to Chainlink Functions. The JavaScript source code makes an API call to the [Star Wars API](https://swapi.dev/) and fetches the name of a given character.
- Set up your web3 wallet and fund it with testnet tokens.
- Simulate a Chainlink Functions on the [Chainlink Functions
Playground](https://functions.chain.link/playground).
- Send a Chainlink Functions request to the DON. The JavaScript source code makes an API call to the [Star Wars API](https://swapi.dev/) and fetches the name of a given character.
- Receive the response from Chainlink Functions and parse the result.

Read the [Examine the code](#examine-the-code) section for a detailed explanation of the code example.

### Simulation
## Simulation

Before making a Chainlink Functions request from your smart contract, it is always a good practice to simulate the source code off-chain to make any adjustments or corrections.

Expand All @@ -52,9 +37,9 @@ Before making a Chainlink Functions request from your smart contract, it is alwa

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

### Configure your resources
## Configure your resources

#### Configure your wallet
### Configure your wallet

You will test on Polygon Mumbai, so you must have an Ethereum web3 wallet with enough MATIC and LINK tokens. MATIC is the native gas fee token on Polygon. You will use MATIC tokens to pay for gas whenever you make a transaction on Polygon Mumbai. On the other hand, you will use LINK tokens to pay the Chainlink Functions Decentralized Oracles Network (DON) for processing your request.

Expand All @@ -74,7 +59,7 @@ You will test on Polygon Mumbai, so you must have an Ethereum web3 wallet with e

1. Request testnet LINK from [faucets.chain.link/mumbai](https://faucets.chain.link/mumbai).

#### Deploy a Functions consumer contract on _Polygon Mumbai_
### Deploy a Functions consumer contract on _Polygon Mumbai_

1. Open the [GettingStartedFunctionsConsumer.sol](https://remix.ethereum.org/#url=https://docs.chain.link/samples/ChainlinkFunctions/GettingStartedFunctionsConsumer.sol) contract in Remix.

Expand All @@ -94,21 +79,21 @@ You will test on Polygon Mumbai, so you must have an Ethereum web3 wallet with e

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

#### Create a subscription
### 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 can find the Chainlink Functions Subscription Manager at [functions.chain.link](https://functions.chain.link/).

### Run the example
## Run the example

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.

To run the example:

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]`.
1. Fill in the `subscriptionId` with your subscription ID and `args` with `[1]`, then click **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" />
Expand Down

0 comments on commit 8c68fab

Please sign in to comment.