Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions docs/docs/developers/guides/js_apps/pay_fees.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,24 @@ import {
} from "@aztec/aztec.js";
```

The FPC contract must be registered in a users PXE before it can be used.
The FPC contract must be registered in a users PXE before it can be used. This will automatically happen if you deploy the FPC to your sandbox, but must be added manually if you are using a standalone PXE.

```ts
import { FPCContract } from "@aztec/noir-contracts.js/FPC";
import { getContractInstanceFromDeployParams } from "@aztec/aztec.js";

// ... (set up the wallet and PXE)

// get the deployed FPC contract instance
const fpcContractInstance = getContractInstanceFromDeployParams(
FPCContract.artifact,
fpcDeployParams // the params used to deploy the FPC
);
// register the already deployed FPC contract in users PXE
const fpcContract = FPCContract.at(fpcAddress, userWallet);
await pxe.registerContract(fpcContract);
await pxe.registerContract({
instance: fpcContractInstance,
artifact: FPCContract.artifact,
});
```

The fee payment method is created and used as follows, with similar syntax for private or public fee payments:
Expand All @@ -154,6 +162,8 @@ The sandbox comes with a sponsored fee paying contract deployed, so this can be
To use sponsored FPCs in other environments, they will need to be deployed and funded with fee juice.
Using a SponsoredFPC payment method is as simple as importing it, registering it and passing it the PXE:

#### Sandbox with PXE

```ts
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
```
Expand All @@ -162,6 +172,8 @@ import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee/testing";
const paymentMethod = new SponsoredFeePaymentMethod(deployedSponsoredFPC);
```

#### Standalone PXE (e.g. Testnet)

Register the SponsoredFPC in the PXE:

```ts
Expand All @@ -170,11 +182,17 @@ import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
// ... (set up the wallet and PXE)

// register the already deployed SponsoredFPC contract in users PXE
const fpcContract = SponsoredFPCContract.at(sponsoredFpcAddress, userWallet);
await pxe.registerContract(fpcContract);
const sponseredFPC = await getSponsoredFPCInstance();
await pxe.registerContract({
instance: sponsoredFPC,
artifact: SponsoredFPCContract.artifact,
});
const paymentMethod = new SponsoredFeePaymentMethod(sponseredFPC.address);
```

Then a transaction can specify this as the `paymentMethod` in the fee object.
You can see an example implementation for `getSponsoredFPCInstance()` [here](https://github.com/AztecProtocol/aztec-packages/blob/360a5f628b4edaf1ea9b328d9e9231f60fdc81a0/yarn-project/aztec/src/sandbox/sponsored_fpc.ts#L5).

Once this is set up, a transaction can specify this as the `paymentMethod` in the fee object.
You can see an example of how to get a deployed instance of the sponsored FPC in the sandbox [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/yarn-project/aztec/src/sandbox/sponsored_fpc.ts#L15).
For example, a contract can be deployed with an fpc as follows:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,13 @@ On this and the following pages in this section, you’ll learn:

Aztec contracts have three different modes of execution: private, public, and utility. How storage is accessed depends on the execution mode: for example, `PublicImmutable` can be read in all execution modes but only initialized in public, while `PrivateMutable` is entirely unavailable in public.

Aztec.nr prevents developers from calling functions unavailable in the current execution mode via the `context` variable that is injected into all contract functions. Its type indicates the current execution mode:
Aztec.nr prevents developers from calling functions unavailable in the current execution mode via the `Context` variable that is injected into all contract functions. Its type indicates the current execution mode:

- `&mut PrivateContext` for private execution
- `&mut PublicContext` for public execution
- `UtilityContext` for utility execution

All state variables are generic over this `Context` type, and expose different methods in each execution mode. In the example above, `PublicImmutable`'s `initialize` function is only available with a public execution context, and so the following code results in a compilation error:

```rust
#[storage]
struct Storage {
variable: PublicImmutable<Field>,
}

#[private]
fn some_private_function() {
storage.variable.initialize(0);
// ^ ERROR: Expected type PublicImmutable<_, &mut PublicContext>, found type PublicImmutable<Field, &mut PrivateContext>
}
```

The `Context` generic type parameter is not visible in the code above as it is automatically injected by the `#[storage]` macro, in order to reduce boilerplate. Similarly, all state variables in that struct (e.g. `PublicImmutable`) similarly have that same type parameter automatically passed to them.
All state variables are generic over this `Context` type, and expose different methods in each execution mode.

## Map

Expand Down