Skip to content

Commit 2fcd32f

Browse files
fix(docs): update to match AddressValidity
1 parent 1e55998 commit 2fcd32f

File tree

1 file changed

+55
-39
lines changed

1 file changed

+55
-39
lines changed

docs/fdc/guides/evm-transaction.mdx

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Each succeeding script will then read that file to load the data.
6161
The JSON request to the verifier is the same form for all attestation types, but the values of the fields differ between them.
6262
It contains the following fields.
6363

64+
### Required Fields
65+
6466
- `attestationType` is the UTF8 hex string encoding of the attestation type name, zero-padded to 32 bytes.
6567
- `sourceId` is the UTF8 hex string encoding of the data source identifier name, zero-padded to 32 bytes.
6668
- `requestBody` is different for each attestation type.
@@ -73,22 +75,29 @@ In the case of `EVMTransaction`, `requestBody` is a JSON containing the fields:
7375
- `listEvents`: a `bool` determining whether the `events` field is included in the response
7476
- `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
7577

78+
### Reference Documentation
79+
7680
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.
7781
Alternatively, we can check the verifier's [interactive docs](https://fdc-verifiers-testnet.flare.network/verifier/api-doc#/ETH/ETHEVMTransactionVerifierController_prepareRequest).
7882
Here we can also check the verifier's response by providing the necessary data.
7983
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).
8084

81-
In our example, the values we will be using are:
85+
### Example Values
8286

8387
- `transactionHash`: `0x4e636c6590b22d8dcdade7ee3b5ae5572f42edb1878f09b3034b2f7c3362ef3c`
8488
- `requiredConfirmations`: `1`
8589
- `provideInput`: `true`
8690
- `listEvents`: `true`
8791
- `logIndices`: `[]`
8892

89-
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.
92101

93102
The first function translates a string to a UTF8 encoded hex string.
94103
The other then zero-right-pads such a string, so that it is 32 bytes long.
@@ -382,11 +391,11 @@ Base.writeToFile(
382391

383392
## 2. Submitting the request to the FDC.
384393

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
386397

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:
390399

391400
```solidity title="scrip/fdcExample/Base.s.sol"
392401
function submitAttestationRequest(bytes memory abiEncodedRequest) internal {
@@ -413,51 +422,60 @@ function submitAttestationRequest(bytes memory abiEncodedRequest) internal {
413422
}
414423
```
415424

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:
417429

418430
```solidity
419-
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
431+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
420432
```
421433

422-
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:
423436

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.
437+
```solidity
438+
IFdcRequestFeeConfigurations fdcRequestFeeConfigurations = ContractRegistry
439+
.getFdcRequestFeeConfigurations();
440+
uint256 requestFee = fdcRequestFeeConfigurations.getRequestFee(
441+
response.abiEncodedRequest
442+
);
427443
428-
We assign the `FcdHub` to a variable, and declare its type as `IFcdHub` (we must import this interface separately).
444+
```
429445

430-
Finally, we can call the `requestAttestation` method of this contract.
431-
But, to execute the transaction, we must pay a certain amount of ether to the contract.
432-
To obtain the exact amount, we call on another contract from the `ContractRegistry` library.
446+
This is done in a separate broadcast to ensure `requestFee` is available before submitting the request.
433447

434-
```solidity title="scrip/fdcExample/Base.s.sol"
435-
IFdcRequestFeeConfigurations fdcRequestFeeConfigurations = ContractRegistry
436-
.getFdcRequestFeeConfigurations();
437-
uint256 requestFee = fdcRequestFeeConfigurations.getRequestFee(
438-
abiEncodedRequest
439-
)
448+
3. Access `FdcHub` Contract
449+
Using the `ContractRegistry` library (from `flare-periphery`), we fetch the `FdcHub` contract:
450+
451+
```solidity
452+
IFdcHub fdcHub = ContractRegistry.getFdcHub();
453+
console.log("fcdHub address:");
454+
console.log(address(fdcHub));
455+
console.log("\n");
440456
```
441457

442-
We do so within a separate broadcast so that the value `requestFee` is available to us when we post the request.
458+
4. Submit the Attestation Request
459+
We send the attestation request with the required fee:
443460

444-
```solidity title="scrip/fdcExample/Base.s.sol"
445-
fdcHub.requestAttestation{requestFee}(abiEncodedRequest);
461+
```solidity
462+
fdcHub.requestAttestation{value: requestFee}(response.abiEncodedRequest);
446463
```
447464

448-
Next, we calculate the voting round number in which the above attestation request takes place.
449-
We do so through the `FlareSystemsManager` contract, which we acquire the same way as we did `FdcHub`.
465+
5. Calculate Voting Round Number
466+
To determine the voting round in which the attestation request is processed, we query the `FlareSystemsManager` contract:
450467

451-
```solidity title="scrip/fdcExample/Base.s.sol"
452-
// Calculating roundId
453-
IFlareSystemsManager flareSystemsManager = ContractRegistry
454-
.getFlareSystemsManager();
468+
```solidity
469+
// Calculating roundId
470+
IFlareSystemsManager flareSystemsManager = ContractRegistry
471+
.getFlareSystemsManager();
472+
473+
uint32 roundId = flareSystemsManager.getCurrentVotingEpochId();
474+
console.log("roundId: %s\n", Strings.toString(roundId));
455475
456-
uint32 roundId = flareSystemsManager.getCurrentVotingEpochId();
457-
console.log("roundId: %s\n", Strings.toString(roundId));
458476
```
459477

460-
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).
461479

462480
Again, we write the `roundId` to a file (`data/EVMTransaction_roundId.txt`).
463481

@@ -627,7 +645,7 @@ We then access the `FdcVerification` contract through the `ContractRegistry`, an
627645
If we proof is valid, the function `verifyEVMTransaction` will return `true`, otherwise `false`.
628646
As before, we wrap the whole thing into a broadcast environment, using the `PRIVATE_KEY` variable from our `.env` file.
629647

630-
```solidity title="scrip/fdcExample/EVMTransaction.s.sol"
648+
```solidity
631649
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
632650
vm.startBroadcast(deployerPrivateKey);
633651
@@ -764,8 +782,6 @@ contract TransferEventListener is ITransferEventListener {
764782
}
765783
```
766784

767-
{/* <!-- TODO --> */}
768-
769785
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`).
770786

771787
```solidity title="scrip/fdcExample/EVMTransaction.s.sol"

0 commit comments

Comments
 (0)