You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -535,8 +536,61 @@ const result = await simulateScript({
535
536
}
536
537
```
537
538
539
+
**_NOTE:_** When running `simulateScript`, depending on your security settings, you may get a popup asking if you would like to accept incoming network connections. You can safely ignore this popup and it should disappear when the simulation is complete.
540
+
538
541
**_NOTE:_** The `simulateScript` function is a debugging tool and hence is not a perfect representation of the actual Chainlink oracle execution environment. Therefore, it is important to make a Functions request on a supported testnet blockchain before mainnet usage.
539
542
543
+
### Local Functions Testnet
544
+
545
+
For debugging smart contracts and the end-to-end request flow on your local machine, you can use the `localFunctionsTestnet` function. This creates a local testnet RPC node with a mock Chainlink Functions contracts. You can then deploy your own Functions consumer contract to this local network, create and manage subscriptions, and send requests. Request processing will simulate the behavior of an actual DON where the request is executed 4 times and the discrete median response is transmitted back to the consumer contract. (Note that Functions uses the following calculation to select the discrete median response: `const medianResponse = responses[responses.length - 1) / 2]`).
546
+
547
+
The `localFunctionsTestnet` function takes the following values as arguments.
simulationConfigPath?: string // Absolute path to config file which exports simulation config parameters
552
+
options?: ServerOptions, // Ganache server options
553
+
port?: number, // Defaults to 8545
554
+
)
555
+
```
556
+
557
+
Observe that `localFunctionsTestnet` takes in a `simulationConfigPath` string as an optional argument. The primary reason for this is because the local testnet does not have the ability to access or decrypt encrypted secrets provided within request transactions. Instead, you can export an object named `secrets` from a TypeScript or JavaScript file and provide the absolute path to that file as the `simulationConfigPath` argument. When the JavaScript code is executed during the request, secrets specified in that file will be made accessible within the JavaScript code regardless of the `secretsLocation` or `encryptedSecretsReference` values sent in the request transaction. This config file can also contain other simulation config parameters. An example of this config file is shown below.
558
+
559
+
```
560
+
export const secrets: { test: 'hello world' } // `secrets` object which can be accessed by the JavaScript code during request execution (can only contain string values)
561
+
export const maxOnChainResponseBytes = 256 // Maximum size of the returned value in bytes (defaults to 256)
562
+
export const maxExecutionTimeMs = 10000 // Maximum execution duration (defaults to 10_000ms)
563
+
export const maxMemoryUsageMb = 128 // Maximum RAM usage (defaults to 128mb)
564
+
export const numAllowedQueries = 5 // Maximum number of HTTP requests (defaults to 5)
565
+
export const maxQueryDurationMs = 9000// Maximum duration of each HTTP request (defaults to 9_000ms)
566
+
export const maxQueryUrlLength = 2048 // Maximum HTTP request URL length (defaults to 2048)
567
+
export const maxQueryRequestBytes = 2048 // Maximum size of outgoing HTTP request payload (defaults to 2048 == 2 KB)
568
+
export const maxQueryResponseBytes = 2097152 // Maximum size of incoming HTTP response payload (defaults to 2_097_152 == 2 MB)
569
+
```
570
+
571
+
`localFunctionsTestnet` returns a promise which resolves to the following type.
getFunds: (address: string, { weiAmount, juelsAmount }: { weiAmount?: BigInt | string; juelsAmount?: BigInt | string }) => Promise<void> // Method which can be called to send funds to any address
578
+
close: () => Promise<void> // Method to close the server
579
+
donId: string // DON ID for simulated DON
580
+
// The following values are all Ethers.js contract types: https://docs.ethers.org/v5/api/contract/contract/
581
+
linkTokenContract: Contract // Mock LINK token contract
Now you can connect to the local Functions testnet RPC node with your preferred blockchain tooling, deploy a FunctionsConsumer contract, instantiate and initialize the`SubscriptionManager`, create, add the consumer contract and fund the subscription, send requests, and use the `ResponseListener` to listen for responses all on your machine.
587
+
588
+
**_NOTE:_** When simulating request executions, depending on your security settings, you may get multiple popups asking if you would like to accept incoming network connections. You can safely ignore these popups and they should disappear when the executions are complete.
589
+
590
+
**_NOTE:_** Cost estimates and other configuration values may differ significantly from actual values on live testnet or mainnet chains.
591
+
592
+
**_NOTE:_** The `localFunctionsTestnet` function is a debugging tool and hence is not a perfect representation of the actual Chainlink oracle execution environment. Therefore, it is important to make a Functions request on a supported testnet blockchain before mainnet usage.
593
+
540
594
### Decoding Response Bytes
541
595
542
596
On-chain responses are encoded as Solidity `bytes` which are most frequently displayed as hex strings. However, these hex strings often need to be decoded into a useable type. In order to decode hex strings into human-readable values, this package provides the `decodeResult` function. Currently, the `decodeResult` function supports decoding hex strings into `uint256`, `int256` or `string` values.
0 commit comments