bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 15쪽
a")
**Type:** Constant
#### BatchedResultSchema[](#batchedresultschema "Direct link to BatchedResultSchema")
**Type:** Constant
#### WalletSchema[](#walletschema "Direct link to WalletSchema")
**Type:** Constant
**Value Type:** `ApiSchemaFor<Wallet>`
---
# Connect to Local Network
This guide shows you how to connect your application to the Aztec local network and interact with the network.
## Prerequisites[](#prerequisites "Direct link to Prerequisites")
* Running Aztec local network (see [Quickstart](/developers/testnet/getting_started_on_local_network.md)) on port 8080
* Node.js installed
* TypeScript project set up
## Install dependencies[](#install-dependencies "Direct link to Install dependencies")
```
yarn add @aztec-labs/aztec.js@6.0.0-rc.1 @aztec-labs/wallets@6.0.0-rc.1
```
## Connect to the network[](#connect-to-the-network "Direct link to Connect to the network")
Create a node client and EmbeddedWallet to interact with the local network:
connect\_to\_network
```
import { createAztecNodeClient, waitForNode } from "@aztec-labs/aztec.js/node";
import { EmbeddedWallet } from "@aztec-labs/wallets/embedded";
import { getInitialTestAccountsData } from "@aztec-labs/accounts/testing";
const nodeUrl = process.env.AZTEC_NODE_URL ?? "http://localhost:8080";
const node = createAztecNodeClient(nodeUrl);
// Wait for the network to be ready
await waitForNode(node);
// Create an EmbeddedWallet connected to the node
const wallet = await EmbeddedWallet.create(node, { ephemeral: true });
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L1-L14](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L1-L14)
About EmbeddedWallet
`EmbeddedWallet` is a simplified wallet for local development that implements the same `Wallet` interface used in production. It handles key management, transaction signing, and proof generation in-process without external dependencies.
**Why use it for testing?** It starts instantly, requires no setup, and provides deterministic behavior—ideal for automated tests and rapid iteration.
**Production wallets** (like browser extensions or mobile apps) implement the same interface but store keys securely, may require user confirmation for transactions, and typically run in a separate process. Code written against `EmbeddedWallet` works with any `Wallet` implementation, so your application logic transfers directly to production.
### Verify the connection[](#verify-the-connection "Direct link to Verify the connection")
Get node information to confirm your connection:
verify\_connection
```
const nodeInfo = await node.getNodeInfo();
console.log("Connected to local network version:", nodeInfo.nodeVersion);
console.log("Chain ID:", nodeInfo.l1ChainId);
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L16-L20](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L16-L20)
### Load pre-funded accounts[](#load-pre-funded-accounts "Direct link to Load pre-funded accounts")
The local network has accounts pre-funded with fee juice to pay for gas. Register them in your wallet:
load\_accounts
```
const testAccounts = await getInitialTestAccountsData();
const [aliceAddress, bobAddress] = await Promise.all(
testAccounts.slice(0, 2).map(async (account) => {
return (
await wallet.createSchnorrInitializerlessAccount(
account.secret,
account.salt,
account.signingKey,
)
).address;
}),
);
console.log(`Alice's address: ${aliceAddress.toString()}`);
console.log(`Bob's address: ${bobAddress.toString()}`);
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L22-L38](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L22-L38)
These accounts are pre-funded with fee juice (the native gas token) at genesis, so you can immediately send transactions without needing to bridge funds from L1.
### Check fee juice balance[](#check-fee-juice-balance "Direct link to Check fee juice balance")
Verify that an account has fee juice for transactions:
check\_fee\_juice
```
import { getFeeJuiceBalance } from "@aztec-labs/aztec.js/utils";
const aliceBalance = await getFeeJuiceBalance(aliceAddress, node);
console.log(`Alice's fee juice balance: ${aliceBalance}`);
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L40-L45](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L40-L45)
## Next steps[](#next-steps "Direct link to Next steps")
* [Create an account](/developers/testnet/docs/aztec-js/how_to_create_account.md) - Deploy new accounts on the network
* [Deploy a contract](/developers/testnet/docs/aztec-js/how_to_deploy_contract.md) - Deploy your smart contracts
* [Send transactions](/developers/testnet/docs/aztec-js/how_to_send_transaction.md) - Execute contract functions
---
# Creating Accounts
This guide shows you how to create and deploy a new account on Aztec.
## Prerequisites[](#prerequisites "Direct link to Prerequisites")
* [Connected to a network](/developers/testnet/docs/aztec-js/how_to_connect_to_local_network.md) with a `EmbeddedWallet` instance
* Understanding of [account concepts](/developers/testnet/docs/foundational-topics/accounts.md)
## Install dependencies[](#install-dependencies "Direct link to Install dependencies")
```
yarn add @aztec-labs/aztec.js@6.0.0-rc.1 @aztec-labs/wallets@6.0.0-rc.1 @aztec-labs/noir-contracts.js@6.0.0-rc.1
```
## Create a new account[](#create-a-new-account "Direct link to Create a new account")
Using the [`wallet` from the connection guide](/developers/testnet/docs/aztec-js/how_to_connect_to_local_network.md), call `createSchnorrAccount` to create a new account with a random secret, salt, and signing key:
create\_account
```
import { Fr, GrumpkinScalar } from "@aztec-labs/aztec.js/fields";
const secret = Fr.random();
const salt = Fr.random();
const signingKey = GrumpkinScalar.random();
const newAccount = await wallet.createSchnorrAccount(secret, salt, signingKey);
console.log("New account address:", newAccount.address.toString());
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L47-L55](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L47-L55)
The secret derives the account's encryption keys, the signing key authenticates its transactions, and the salt ensures address uniqueness. The signing key is provided independently and is not derived from the secret: it is an ownership key, so keep it separate from the encryption secret that your PXE holds.
Store your secret, salt, and signing key
Save the `secret`, `salt`, and `signingKey` values securely. You need all three to recover access to your account. If you lose them, you will permanently lose access to the account and any assets it holds.
## Deploy the account[](#deploy-the-account "Direct link to Deploy the account")
New accounts must be deployed before they can send transactions. Deployment requires paying fees.
### Using the Sponsored FPC[](#using-the-sponsored-fpc "Direct link to Using the Sponsored FPC")
If your account doesn't have Fee Juice, use the [Sponsored FPC](/developers/testnet/docs/aztec-js/how_to_pay_fees.md#sponsored-fpc):
deploy\_account\_sponsored\_fpc
```
// Additional imports needed for account deployment examples
import { NO_FROM } from "@aztec-labs/aztec.js/account";
import { SponsoredFeePaymentMethod } from "@aztec-labs/aztec.js/fee/testing";
import { SponsoredFPCContract } from "@aztec-labs/noir-contracts.js/SponsoredFPC";
import { getContractInstanceFromInstantiationParams } from "@aztec-labs/stdlib/contract";
// Set up the Sponsored FPC payment method (see fees guide for details)
const sponsoredFPCInstance = await getContractInstanceFromInstantiationParams(
SponsoredFPCContract.artifact,
{ salt: new Fr(0) },
);
await wallet.registerContract(
sponsoredFPCInstance,
SponsoredFPCContract.artifact,
);
const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(
sponsoredFPCInstance.address,
);
// newAccount is the account created in the previous section
const deployMethod = await newAccount.getDeployMethod();
await deployMethod.send({
from: NO_FROM,
fee: { paymentMethod: sponsoredPaymentMethod },
});
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L57-L83](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L57-L83)
info
See the [guide on fees](/developers/testnet/docs/aztec-js/how_to_pay_fees.md#sponsored-fpc) for more details on the Sponsored FPC and what this snippet means.
### Using Fee Juice[](#using-fee-juice "Direct link to Using Fee Juice")
If your account has Fee Juice from a [bridge from L1](/developers/testnet/docs/aztec-js/how_to_pay_fees.md#bridge-fee-juice-from-l1), you can claim it and deploy in one step using `FeeJuicePaymentMethodWithClaim`.
Create a new Schnorr account for this path:
create\_fee\_juice\_account
```
// `feeJuiceAccount` is just another Schnorr account, the same kind as
// `newAccount` above. It gets its own name here so both deploy paths
// can coexist in one example; in your own code, pick whichever name fits.
const feeJuiceSecret = Fr.random();
const feeJuiceSalt = Fr.random();
const feeJuiceSigningKey = GrumpkinScalar.random();
const feeJuiceAccount = await wallet.createSchnorrAccount(
feeJuiceSecret,
feeJuiceSalt,
feeJuiceSigningKey,
);
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L85-L97](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L85-L97)
Claim the bridged Fee Juice and deploy in one step:
bridge\_fee\_juice\_claim
```
import { FeeJuicePaymentMethodWithClaim } from "@aztec-labs/aztec.js/fee";
// claim is from the bridgeTokensPublic step above
// Create a payment method that claims the bridged Fee Juice and uses it to pay
const bridgePaymentMethod = new FeeJuicePaymentMethodWithClaim(
feeJuiceAccount.address,
claim,
);
// Use it to pay for any transaction; here we deploy the account in one step
const deployMethodBridged = await feeJuiceAccount.getDeployMethod();
await deployMethodBridged.send({
from: NO_FROM,
fee: { paymentMethod: bridgePaymentMethod },
});
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L166-L182](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L166-L182)
If the account already has Fee Juice on L2 (for example, from a faucet or a previously claimed bridge), no special payment method is needed — just call `send({ from: NO_FROM })` and Fee Juice is used automatically.
The `from: NO_FROM` signals that this transaction should be executed without account contract mediation. The wallet will directly execute it via a default entrypoint with no authorization.
## Verify deployment[](#verify-deployment "Direct link to Verify deployment")
Confirm the account was deployed successfully. Substitute the account variable for whichever path you used above (`newAccount` for the Sponsored FPC path, `feeJuiceAccount` for the Fee Juice path):
verify\_account\_deployment
```
// `newAccount` refers to whichever account you just deployed,
// either the Sponsored FPC account or `feeJuiceAccount` from the Fee Juice path.
const metadata = await wallet.getContractMetadata(newAccount.address);
console.log("Account deployed:", metadata.initializationStatus);
```
> [Source code: docs/examples/ts/aztecjs\_connection/index.ts#L184-L189](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_connection/index.ts#L184-L189)
## Next steps[](#next-steps "Direct link to Next steps")
* [Deploy contracts](/developers/testnet/docs/aztec-js/how_to_deploy_contract.md) with your new account
* [Send transactions](/developers/testnet/docs/aztec-js/how_to_send_transaction.md) from an account
* Learn about [account abstraction](/developers/testnet/docs/foundational-topics/accounts.md)
* Implement [authentication witnesses](/developers/testnet/docs/aztec-js/how_to_use_authwit.md)
---
# Deploying Contracts
This guide shows you how to deploy compiled contracts to Aztec using the generated TypeScript interfaces.
## Overview[](#overview "Direct link to Overview")
Deploying a contract to Aztec involves publishing the contract class (the bytecode) and creating a contract instance at a specific address. The generated TypeScript classes handle this process through an API: you call `deploy()` with constructor arguments and `send()` with transaction options to deploy and get the contract instance. The contract address is deterministically computed from the contract class, constructor arguments, salt, and deployer address.
<!-- -->
## Prerequisites[](#prerequisites "Direct link to Prerequisites")
* Compiled contract artifacts (see [How to Compile](/developers/testnet/docs/aztec-nr/compiling_contracts.md))
* [Connected to a network](how_to_connect_to_local_network) with an
<!-- -->
`EmbeddedWallet` instance and funded accounts
<!-- -->
* TypeScript project set up
## Generate TypeScript bindings[](#generate-typescript-bindings "Direct link to Generate TypeScript bindings")
### Compile and generate code[](#compile-and-generate-code "Direct link to Compile and generate code")
```
# Compile the contract
aztec compile
# Generate TypeScript interface
aztec codegen ./target/my_contract-MyContract.json -o src/artifacts
```
info
The codegen command creates a TypeScript class with typed methods for deployment and interaction. This provides type safety and autocompletion in your IDE.
## Deploy a contract[](#deploy-a-contract "Direct link to Deploy a contract")
### Step 1: Import and connect[](#step-1-import-and-connect "Direct link to Step 1: Import and connect")
```
import { MyContract } from "./artifacts/MyContract";
```
About wallets and accounts
In the examples below, `wallet` refers to a `Wallet` instance that manages keys and signs transactions. See [Creating Accounts](/developers/testnet/docs/aztec-js/how_to_create_account.md) for how to set up a wallet. The `from` option in `send()` specifies which account pays for the transaction. This account must be registered in the wallet and have sufficient fee juice. On a local network, test accounts are pre-funded; on testnet, you typically use sponsored fees.
### Step 2: Deploy the contract[](#step-2-deploy-the-contract "Direct link to Step 2: Deploy the contract")
How you deploy depends on how you pay for it. When paying using an account's fee juice (like a test account on the local network):
deploy\_basic\_local
```
// wallet and aliceAddress are from the connection guide
// Deploy with constructor arguments
const { contract: token } = await TokenContract.deploy(
wallet,
aliceAddress,
"TestToken",
"TST",
18,
).send({ from: aliceAddress }); // alice has fee juice and is registered in the wallet
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L38-L48](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L38-L48)
On testnet, your account likely won't have Fee Juice. Instead, pay fees using the [Sponsored Fee Payment Contract method](/developers/testnet/docs/aztec-js/how_to_pay_fees.md):
deploy\_sponsored\_fpc\_contract
```
// Set up the Sponsored FPC (see fees guide for full setup)
const sponsoredFPCInstance = await getContractInstanceFromInstantiationParams(
SponsoredFPCContract.artifact,
{ salt: new Fr(0) },
);
await wallet.registerContract(
sponsoredFPCInstance,
SponsoredFPCContract.artifact,
);
const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(
sponsoredFPCInstance.address,
);
// wallet is from the connection guide; sponsoredPaymentMethod is from the fees guide
const { contract: sponsoredContract } = await TokenContract.deploy(
wallet,
aliceAddress,
"SponsoredToken",
"SPT",
18,
).send({ from: aliceAddress, fee: { paymentMethod: sponsoredPaymentMethod } });
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L50-L72](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L50-L72)
Here's a complete example from the test suite:
deploy\_basic
```
const { contract } = await StatefulTestContract.deploy(wallet, owner, 42).send({ from: defaultAccountAddress });
```
> [Source code: yarn-project/end-to-end/src/automine/contracts/deploy/deploy\_method.parallel.test.ts#L47-L49](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#L47-L49)
## Use deployment options[](#use-deployment-options "Direct link to Use deployment options")
### Deploy with custom salt[](#deploy-with-custom-salt "Direct link to Deploy with custom salt")
By default, the deployment's salt is random, but you can specify it (for example, if you want to get a deterministic address):
deploy\_custom\_salt
```
// wallet and aliceAddress are from the connection guide
const customSalt = Fr.random();
const { contract: saltedContract } = await TokenContract.deploy(
wallet,
aliceAddress,
"SaltedToken",
"SALT",
18,
{ salt: customSalt },
).send({
from: aliceAddress,
});
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L74-L88](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L74-L88)
### Deploy universally[](#deploy-universally "Direct link to Deploy universally")
Deploy to the same address across networks by setting `universalDeploy: true`:
deploy\_universal
```
const opts = { universalDeploy: true, from: defaultAccountAddress };
const { contract } = await StatefulTestContract.deploy(wallet, owner, 42).send(opts);
```
> [Source code: yarn-project/end-to-end/src/automine/contracts/deploy/deploy\_method.parallel.test.ts#L66-L69](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#L66-L69)
info
Universal deployment excludes the sender from address computation, allowing the same address on any network with the same salt.
### Skip initialization[](#skip-initialization "Direct link to Skip initialization")
Deploy without running the constructor:
skip\_initialization
```
// Deploy without running the constructor using skipInitialization
const { contract: delayedToken } = await TokenContract.deploy(
wallet,
aliceAddress,
"DelayedToken",
"DLY",
18,
).send({
from: aliceAddress,
skipInitialization: true,
});
console.log(`Contract deployed at: ${delayedToken.address}`);
// Initialize later by calling the constructor manually
await delayedToken.methods
.constructor(aliceAddress, "DelayedToken", "DLY", 18)
.send({ from: aliceAddress });
console.log("Contract initialized");
```
> [Source code: docs/examples/ts/aztecjs\_advanced/index.ts#L274-L295](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/docs/examples/ts/aztecjs_advanced/index.ts#L274-L295)
### Deploy with a specific initializer[](#deploy-with-a-specific-initializer "Direct link to Deploy with a specific initializer")
Some contracts have multiple initializer functions (e.g., both a private `constructor` and a `public_constructor`). By default, the generated `deploy()` method uses the default initializer (typically named `constructor`). To deploy using a different initializer, use `deployWithOpts`:
deploy\_with\_opts
```
const { contract } = await StatefulTestContract.deployWithOpts(
{ wallet, method: 'public_constructor' },
owner,
42,
).send({
from: defaultAccountAddress,
});
```
> [Source code: yarn-project/end-to-end/src/auto프로젝트로 돌아가기