bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 16쪽
mine/contracts/deploy/deploy\_method.parallel.test.ts#L90-L98](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/yarn-project/end-to-end/src/automine/contracts/deploy/deploy_method.parallel.test.ts#L90-L98)
The `deployWithOpts` method accepts an options object as its first argument:
* `wallet`: The wallet to use for deployment (required)
* `method`: The name of the initializer function to call (optional, defaults to `constructor`)
* `publicKeys`: Custom public keys for the contract instance (optional)
The remaining arguments are the parameters for the chosen initializer function.
tip
This is useful for contracts that support multiple initialization patterns, such as token standards that allow both private and public minting during deployment.
## Calculate deployment address[](#calculate-deployment-address "Direct link to Calculate deployment address")
### Get address before deployment[](#get-address-before-deployment "Direct link to Get address before deployment")
calculate\_address\_before\_deploy
```
// Calculate address without deploying
// wallet is from the connection guide (see prerequisites)
const deploymentSalt = Fr.random();
const deployMethod = TokenContract.deploy(
wallet,
aliceAddress,
"PredictedToken",
"PRED",
18,
{ salt: deploymentSalt, deployer: aliceAddress },
);
const instance = await deployMethod.getInstance();
const predictedAddress = instance.address;
console.log(`Contract will deploy at: ${predictedAddress}`);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L90-L106](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L90-L106)
warning
This is an advanced pattern. For most use cases, deploy the contract directly and get the address from the deployed instance.
## Monitor deployment progress[](#monitor-deployment-progress "Direct link to Monitor deployment progress")
### Track deployment transaction[](#track-deployment-transaction "Direct link to Track deployment transaction")
Use `NO_WAIT` to get the transaction hash immediately and track deployment:
no\_wait\_deploy
```
// Use NO_WAIT to get the transaction hash immediately and track deployment
const { txHash } = await TokenContract.deploy(
wallet,
aliceAddress,
"AnotherToken",
"ATK",
18,
).send({
from: aliceAddress,
wait: NO_WAIT,
});
console.log(`Deployment tx: ${txHash}`);
// Wait for the transaction to be mined using the node
const receipt = await waitForTx(node, txHash);
console.log(`Deployed in block ${receipt.blockNumber}`);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L147-L165](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L147-L165)
For most use cases, simply await the deployment to get the contract directly:
deploy\_contract
```
import { TokenContract } from "@aztec-labs/noir-contracts.js/Token";
const { contract: token } = await TokenContract.deploy(
wallet,
aliceAddress,
"TestToken",
"TST",
18,
).send({ from: aliceAddress });
console.log(`Token deployed at: ${token.address.toString()}`);
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L128-L140](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L128-L140)
## Deploy multiple contracts[](#deploy-multiple-contracts "Direct link to Deploy multiple contracts")
### Deploy a token contract[](#deploy-a-token-contract "Direct link to Deploy a token contract")
Here's an example deploying a `TokenContract` with constructor arguments for admin, name, symbol, and decimals:
deploy\_token
```
const { contract: token } = await TokenContract.deploy(wallet, owner, 'TOKEN', 'TKN', 18).send({
from: defaultAccountAddress,
});
```
> [Source code: yarn-project/end-to-end/src/automine/contracts/deploy/deploy\_method.parallel.test.ts#L79-L83](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/yarn-project/end-to-end/src/automine/contracts/deploy/deploy_method.parallel.test.ts#L79-L83)
### Deploy contracts with dependencies[](#deploy-contracts-with-dependencies "Direct link to Deploy contracts with dependencies")
When one contract depends on another, deploy them sequentially and pass the first contract's address:
deploy\_with\_dependencies
```
// Deploy contracts with dependencies - deploy sequentially and pass addresses
const { contract: baseToken } = await TokenContract.deploy(
wallet,
aliceAddress,
"BaseToken",
"BASE",
18,
).send({ from: aliceAddress });
// A second contract could reference the first (example pattern)
const { contract: derivedToken } = await TokenContract.deploy(
wallet,
baseToken.address, // Use first contract's address as admin
"DerivedToken",
"DERIV",
18,
).send({ from: aliceAddress });
console.log(`Base token at: ${baseToken.address.toString()}`);
console.log(`Derived token at: ${derivedToken.address.toString()}`);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L226-L247](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L226-L247)
### Deploy contracts in parallel[](#deploy-contracts-in-parallel "Direct link to Deploy contracts in parallel")
parallel\_deploy
```
// Deploy contracts in parallel using Promise.all
const contracts = await Promise.all([
TokenContract.deploy(wallet, aliceAddress, "Token1", "T1", 18)
.send({
from: aliceAddress,
})
.then(({ contract }) => contract),
TokenContract.deploy(wallet, aliceAddress, "Token2", "T2", 18)
.send({
from: aliceAddress,
})
.then(({ contract }) => contract),
TokenContract.deploy(wallet, aliceAddress, "Token3", "T3", 18)
.send({
from: aliceAddress,
})
.then(({ contract }) => contract),
]);
console.log(`Contract 1 at: ${contracts[0].address}`);
console.log(`Contract 2 at: ${contracts[1].address}`);
console.log(`Contract 3 at: ${contracts[2].address}`);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L249-L272](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L249-L272)
Parallel deployment considerations
Parallel deployment is faster, but transactions from the same account share a nonce sequence. The wallet handles nonce assignment automatically, but if one deployment fails, subsequent deployments may also fail due to nonce gaps. For reliable parallel deployments:
* Use separate accounts for each deployment, or
* Handle failures gracefully and retry with fresh nonces
* Consider using `BatchCall` to bundle multiple operations into a single transaction (see below)
### Deploy with BatchCall[](#deploy-with-batchcall "Direct link to Deploy with BatchCall")
Use `BatchCall` to bundle a deployment with other calls into a single transaction. This is useful when you need to deploy a contract and immediately call methods on it:
deploy\_batch
```
// Create a contract instance and make the PXE aware of it
const deployMethod = StatefulTestContract.deploy(wallet, owner, 42, { deployer: defaultAccountAddress });
const contract = await deployMethod.register();
// Batch deployment and a public call into the same transaction
const publicCall = contract.methods.increment_public_value(owner, 84);
await new BatchCall(wallet, [deployMethod, publicCall]).send({ from: defaultAccountAddress });
```
> [Source code: yarn-project/end-to-end/src/automine/contracts/deploy/deploy\_method.parallel.test.ts#L170-L178](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/yarn-project/end-to-end/src/automine/contracts/deploy/deploy_method.parallel.test.ts#L170-L178)
## Verify deployment[](#verify-deployment "Direct link to Verify deployment")
### Check contract state[](#check-contract-state "Direct link to Check contract state")
Use `wallet.getContractMetadata()` to check your contract's current state:
```
const metadata = await wallet.getContractMetadata(contractAddress);
// Check each state:
metadata.instance; // Contract registered in your wallet?
metadata.isContractClassPubliclyRegistered; // Class registered on the network?
metadata.isContractPublished; // Instance registered on the network?
metadata.initializationStatus; // Constructor has been called?
```
For a complete overview of what these states mean and when functions become callable, see [Contract Readiness States](/developers/testnet/docs/aztec-nr/contract_readiness_states.md).
Here's a complete example:
verify\_deployment
```
const metadata = await wallet.getContractMetadata(contract.address);
const classMetadata = await wallet.getContractClassMetadata(metadata.instance!.originalContractClassId);
const isPublished = classMetadata.isContractClassPubliclyRegistered;
```
> [Source code: yarn-project/end-to-end/src/automine/contracts/deploy/deploy\_method.parallel.test.ts#L56-L60](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/yarn-project/end-to-end/src/automine/contracts/deploy/deploy_method.parallel.test.ts#L56-L60)
### What the PXE checks automatically[](#what-the-pxe-checks-automatically "Direct link to What the PXE checks automatically")
When you simulate or send a transaction, the PXE automatically verifies:
* Contract instance is registered in your wallet
* Contract artifact is available locally
* Contract class ID matches the network state
The PXE does **not** automatically check:
* Whether the contract is published on the network
* Whether the contract is initialized
* Whether the contract class is registered on the network
If you call a public function on an unpublished contract, the transaction will fail at the network level, not during local simulation. Use `getContractMetadata()` to check these states before sending transactions if you want to provide better error messages to users.
### Verify contract is callable[](#verify-contract-is-callable "Direct link to Verify contract is callable")
verify\_contract\_callable
```
// token is from the deployment step above; aliceAddress is from the connection guide
try {
// Try calling a view function
const { result: balance } = await token.methods
.balance_of_public(aliceAddress)
.simulate({ from: aliceAddress });
console.log("Contract is callable, balance:", balance);
} catch (error) {
console.error("Contract not accessible:", (error as Error).message);
}
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L108-L119](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L108-L119)
## Register deployed contracts[](#register-deployed-contracts "Direct link to Register deployed contracts")
### Add existing contract to wallet[](#add-existing-contract-to-wallet "Direct link to Add existing contract to wallet")
If a contract was deployed by another account:
register\_external\_contract
```
// wallet is from the connection guide; contractAddress is the address of the deployed contract
const contractAddress = token.address;
// Get the contract metadata from the node (includes the instance)
const metadata = await wallet.getContractMetadata(contractAddress);
// Register the contract with the wallet
// The registerContract method takes positional parameters:
// - instance: ContractInstanceWithAddress (required)
// - artifact: ContractArtifact (optional)
// - secretKey: Fr (optional)
await wallet.registerContract(metadata.instance!, TokenContract.artifact);
// Now you can interact with the contract
const externalContract = await TokenContract.at(contractAddress, wallet);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L121-L137](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L121-L137)
warning
You need the exact deployment parameters (salt, initialization hash, etc.) to correctly register an externally deployed contract. If you don't have access to the contract instance, you can reconstruct it:
reconstruct\_contract\_instance
```
// Reconstruct a contract instance from deployment parameters
// Use this when you need to register a contract deployed by someone else
const reconstructedInstance = await getContractInstanceFromInstantiationParams(
TokenContract.artifact,
{
publicKeys: PublicKeys.default(),
constructorArtifact: "constructor",
constructorArgs: [aliceAddress, "ReconstructedToken", "RTK", 18],
deployer: aliceAddress,
salt: new Fr(12345), // The original deployment salt
},
);
// Register the reconstructed contract with the wallet
await wallet.registerContract(reconstructedInstance, TokenContract.artifact);
console.log(
`Reconstructed contract address: ${reconstructedInstance.address.toString()}`,
);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L191-L210](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L191-L210)
## Next steps[](#next-steps "Direct link to Next steps")
* [Contract Readiness States](/developers/testnet/docs/aztec-nr/contract_readiness_states.md) - Understand the different states a contract progresses through
* [Send transactions](/developers/testnet/docs/aztec-js/how_to_send_transaction.md) to interact with your contract
* [Read contract data](/developers/testnet/docs/aztec-js/how_to_read_data.md) including simulating functions and reading events
* [Use authentication witnesses](/developers/testnet/docs/aztec-js/how_to_use_authwit.md) for delegated calls
---
# Paying Fees
This guide walks you through paying transaction fees on Aztec using various payment methods.
## Prerequisites[](#prerequisites "Direct link to Prerequisites")
* [Connected to a network](how_to_connect_to_local_network) with an
<!-- -->
`EmbeddedWallet` instance and funded accounts
<!-- -->
* Understanding of [fee concepts](/developers/testnet/docs/foundational-topics/fees.md)
info
The fee asset is only transferrable within a block to the current sequencer, as it powers the fee abstraction mechanism on Aztec. The asset is not transferable beyond this to ensure credible neutrality between all third party developer made asset portals and to ensure local compliance rules can be followed.
## Payment methods overview[](#payment-methods-overview "Direct link to Payment methods overview")
| Method | Use Case | Privacy | Requirements |
| ------------------- | -------------------------------------- | ------------- | ------------------------- |
| Fee Juice (default) | Account already has Fee Juice | Public | Funded account |
| Sponsored FPC | Testing, free transactions | Public | None |
| Private FPC | Privacy-preserving fees | Private | Bridged Fee Juice via FPC |
| Third-party FPC | Pay in other tokens on testnet/mainnet | Varies by FPC | FPC provider's SDK |
| Bridge + Claim | Bootstrap from L1 | Public | L1 ETH for gas |
## Mana and Fee Juice[](#mana-and-fee-juice "Direct link to Mana and Fee Juice")
Mana is Aztec's unit of computational effort (like gas on Ethereum), and Fee Juice is the native fee token used to pay for transactions. For a detailed explanation of these concepts, see [Fee Concepts](/developers/testnet/docs/foundational-topics/fees.md).
## Estimate mana costs[](#estimate-mana-costs "Direct link to Estimate mana costs")
Automatic estimation with EmbeddedWallet
When using `EmbeddedWallet`, gas is estimated automatically on every `send()` call. You only need to manually estimate if you want to preview costs before sending, or if you're using a custom wallet implementation.
Before sending a transaction, you can read the mana it will consume by simulating with `includeMetadata: true` and reading `gasUsed` from the result:
estimate\_mana
```
const { gasUsed } = await token.methods
.transfer_in_public(aliceAddress, bobAddress, 1n, 0n)
.simulate({ from: aliceAddress, includeMetadata: true });
// Pad the raw usage yourself to leave headroom for variance, e.g. 10%.
const estimatedGasLimits = gasUsed!.totalGas.mul(1.1);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L378-L384](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L378-L384)
The `gasUsed` object contains the raw gas the simulation consumed:
* `totalGas.daGas` / `totalGas.l2Gas` - DA and L2 mana consumed across the whole transaction
* `teardownGas.daGas` / `teardownGas.l2Gas` - DA and L2 mana consumed in the teardown phase
It is up to you to derive the gas limits you declare from this raw usage (typically by padding it, as shown above). If you don't declare any gas limits, the wallet fills in the network's per-tx admission limits for you.
### Calculate expected fee from estimate[](#calculate-expected-fee-from-estimate "Direct link to Calculate expected fee from estimate")
To calculate the expected fee from the padded gas, use the `computeFee` method with current network fees:
compute\_fee\_from\_estimate
```
const currentFees = await node.getCurrentMinFees();
const estimatedFee = estimatedGasLimits.computeFee(currentFees).toBigInt();
console.log("Estimated fee:", estimatedFee);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L386-L390](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L386-L390)
tip
Pad the raw `gasUsed` yourself to leave a safety margin. Multiplying by `1.1` adds 10%; use higher padding for transactions with variable gas costs. The wallet rejects any declared limit above the network's per-tx admission limit.
## Get transaction fee from receipt[](#get-transaction-fee-from-receipt "Direct link to Get transaction fee from receipt")
After a transaction is mined, you can retrieve the fee paid from the receipt:
get\_fee\_from\_receipt
```
const { receipt: feeReceipt } = await token.methods
.mint_to_public(aliceAddress, 1n)
.send({ from: aliceAddress });
console.log("Transaction fee:", feeReceipt.transactionFee);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L392-L397](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L392-L397)
The `transactionFee` field is a `bigint` representing the total fee paid in the fee token (Fee Juice). You can also check execution status:
check\_receipt\_status
```
console.log("Succeeded:", feeReceipt.hasExecutionSucceeded());
console.log("Block:", feeReceipt.blockNumber);
console.log("Fee paid:", feeReceipt.transactionFee);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L399-L403](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L399-L403)
## Pay with Fee Juice[](#pay-with-fee-juice "Direct link to Pay with Fee Juice")
Fee Juice is the native fee token on Aztec.
If your account has Fee Juice (for example, from a faucet), is [deployed](/developers/testnet/docs/aztec-js/how_to_create_account.md), and is registered in your wallet, it will be used automatically to pay for the fee of the transaction:
pay\_with\_fee\_juice
```
// contract is a deployed contract instance; aliceAddress is from the connection guide
const { receipt: feeJuiceReceipt } = await token.methods
.mint_to_public(aliceAddress, 1n)
.send({
from: aliceAddress,
// no fee payment method needed; Fee Juice is used automatically
});
console.log("Transaction fee:", feeJuiceReceipt.transactionFee);
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L405-L414](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L405-L414)
## Use Fee Payment Contracts[](#use-fee-payment-contracts "Direct link to Use Fee Payment Contracts")
Fee Payment Contracts (FPCs) pay Fee Juice on your behalf. An FPC holds its own Fee Juice balance to pay the protocol and can accept other tokens from users in exchange. Some FPCs operate privately by d프로젝트로 돌아가기