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
Copy file name to clipboardExpand all lines: docs/fdc/guides/evm-transaction.mdx
+55-39Lines changed: 55 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,8 @@ Each succeeding script will then read that file to load the data.
61
61
The JSON request to the verifier is the same form for all attestation types, but the values of the fields differ between them.
62
62
It contains the following fields.
63
63
64
+
### Required Fields
65
+
64
66
-`attestationType` is the UTF8 hex string encoding of the attestation type name, zero-padded to 32 bytes.
65
67
-`sourceId` is the UTF8 hex string encoding of the data source identifier name, zero-padded to 32 bytes.
66
68
-`requestBody` is different for each attestation type.
@@ -73,22 +75,29 @@ In the case of `EVMTransaction`, `requestBody` is a JSON containing the fields:
73
75
-`listEvents`: a `bool` determining whether the `events` field is included in the response
74
76
-`logIndices`: an `uint32` array of indices of the events to be included in the response; if `listEvents` is set to false `false` and this field is not `[]`, the attestation request will fail
75
77
78
+
### Reference Documentation
79
+
76
80
We can find the required fields in the [specification](https://gitlab.com/flarenetwork/docs-team/flare-specs/-/blob/main/src/FDC/AttestationTypes/EVMTransaction.md?ref_type=heads) for the `EVMTransaction` attestation type.
77
81
Alternatively, we can check the verifier's [interactive docs](https://fdc-verifiers-testnet.flare.network/verifier/api-doc#/ETH/ETHEVMTransactionVerifierController_prepareRequest).
78
82
Here we can also check the verifier's response by providing the necessary data.
79
83
Though the URLs are slightly different, the verifier has the same API for both [FLR](https://fdc-verifiers-testnet.flare.network/verifier/flr/api-doc#/AddressValidity/BTCAddressValidityVerifierController_prepareRequest) and [SGB](https://fdc-verifiers-testnet.flare.network/verifier/sgb/api-doc#/AddressValidity/BTCAddressValidityVerifierController_prepareRequest).
To produce the UTF8 hex string encoding of a given value, we define the `toUtf8HexString` and `toHexString` helper functions.
90
-
In the [example repository](https://github.com/flare-foundation/flare-foundry-starter), these are shipped within an [Base](https://github.com/flare-foundation/flare-foundry-starter/blob/master/script/fdcExample/Base.s.sol) library, since all attestation type examples make use of them.
91
-
But you may as well define them within the same contract or within the same file.
93
+
### Encoding Functions
94
+
95
+
To encode values into UTF8 hex:
96
+
97
+
-`toUtf8HexString`: Converts a string to UTF8 hex.
98
+
-`toHexString`: Zero-right-pads the string to 32 bytes.
99
+
100
+
These functions are included in the [Base library](https://github.com/flare-foundation/flare-foundry-starter/blob/master/script/fdcExample/Base.s.sol) within the [example repository](https://github.com/flare-foundation/flare-foundry-starter), but they can also be defined locally in your contract or script.
92
101
93
102
The first function translates a string to a UTF8 encoded hex string.
94
103
The other then zero-right-pads such a string, so that it is 32 bytes long.
@@ -382,11 +391,11 @@ Base.writeToFile(
382
391
383
392
## 2. Submitting the request to the FDC.
384
393
385
-
In contrast to the previous steps, which took many lines of code that required little explanation, we really need only five to submit the request to the `FdcHub` protocol, but all of them require a closer look.
394
+
This step transitions from off-chain request preparation to on-chain interaction with the FDC protocol. Now, we submit the validated request to the blockchain using deployed smart contracts.
395
+
396
+
### Submitting the Request
386
397
387
-
:::note
388
-
So far, everything has been happening off-chain; in this step, we will start interacting with deployed contracts.
389
-
:::
398
+
The entire submission process requires only five key steps:
390
399
391
400
```solidity title="scrip/fdcExample/Base.s.sol"
392
401
function submitAttestationRequest(bytes memory abiEncodedRequest) internal {
@@ -413,51 +422,60 @@ function submitAttestationRequest(bytes memory abiEncodedRequest) internal {
413
422
}
414
423
```
415
424
416
-
First of all, we read the private key of our account from a `.env` file using a Foundry shortcode:
425
+
### Step-by-Step Breakdown
426
+
427
+
1. Load Private Key
428
+
The private key is read from the `.env` file using Foundry's `envUint` function:
We then broadcast all the code enveloped between `vm.startBroadcast` and `vm.stopBroadcast` shortcodes, to the chain (the console command parameter `--rpc-url` determines which one).
434
+
2. Obtain Request Fee
435
+
We retrieve the required requestFee from the `FdcRequestFeeConfigurations` contract:
423
436
424
-
To acquire access to the `FcdHub` contract, we first import the `ContractRegistry` library from the `flare-periphery` package.
425
-
The purpose of this library is to provide getter functions for the most commonly used Flare contracts.
426
-
It calls the `getContractAddressByName("FdcHub")` function of the `ContractRegistry` contract, deployed on the correct address.
We can either do that within the previous broadcast or start a new one (in the demo repository, we chose the second option, because it allowed us to organize the code better).
478
+
This can be done within the existing broadcast or in a new one (as done in the demo repository for better code organization).
461
479
462
480
Again, we write the `roundId` to a file (`data/EVMTransaction_roundId.txt`).
463
481
@@ -627,7 +645,7 @@ We then access the `FdcVerification` contract through the `ContractRegistry`, an
627
645
If we proof is valid, the function `verifyEVMTransaction` will return `true`, otherwise `false`.
628
646
As before, we wrap the whole thing into a broadcast environment, using the `PRIVATE_KEY` variable from our `.env` file.
@@ -764,8 +782,6 @@ contract TransferEventListener is ITransferEventListener {
764
782
}
765
783
```
766
784
767
-
{/* <!-- TODO --> */}
768
-
769
785
We deploy the contract through a simple script. The script creates a new `TransferEventListener` contract, and writes its address to a file (`data/EVMTransaction_listenerAddress.txt`).
0 commit comments