Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions boxes/boxes/react/src/hooks/useContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ export function useContract() {

const { BoxReactContract } = await import('../../artifacts/BoxReact');

const tx = await BoxReactContract.deploy(wallet, Fr.random(), defaultAccountAddress).send({
const deploymentPromise = BoxReactContract.deploy(wallet, Fr.random(), defaultAccountAddress).send({
from: defaultAccountAddress,
contractAddressSalt: salt,
});
const contract = await toast.promise(tx.deployed(), {

const contract = await toast.promise(deploymentPromise, {
pending: 'Deploying contract...',
success: {
render: ({ data }) => `Address: ${data.address}`,
Expand Down
2 changes: 1 addition & 1 deletion boxes/boxes/react/src/hooks/useNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function useNumber({ contract }: { contract: Contract }) {
const value = BigInt(el.value);
const defaultAccountAddress = deployerEnv.getDefaultAccountAddress();
await toast.promise(
contract!.methods.setNumber(value, defaultAccountAddress).send({ from: defaultAccountAddress }).wait(),
contract!.methods.setNumber(value, defaultAccountAddress).send({ from: defaultAccountAddress }),
{
pending: 'Setting number...',
success: `Number set to: ${value}`,
Expand Down
10 changes: 7 additions & 3 deletions boxes/boxes/vanilla/app/embedded-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Account, SignerlessAccount } from '@aztec/aztec.js/account';
import { AztecAddress } from '@aztec/aztec.js/addresses';
import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
import {
getContractInstanceFromInstantiationParams,
InteractionWaitOptions,
} from '@aztec/aztec.js/contracts';
import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee';
import { Fr } from '@aztec/aztec.js/fields';
import { createLogger } from '@aztec/aztec.js/log';
Expand Down Expand Up @@ -218,7 +221,7 @@ export class EmbeddedWallet extends BaseWallet {
const deployMethod = await accountManager.getDeployMethod();
const sponsoredPFCContract =
await EmbeddedWallet.#getSponsoredPFCContract();
const deployOpts: DeployAccountOptions = {
const deployOpts: DeployAccountOptions<InteractionWaitOptions> = {
from: AztecAddress.ZERO,
fee: {
paymentMethod: new SponsoredFeePaymentMethod(
Expand All @@ -227,9 +230,10 @@ export class EmbeddedWallet extends BaseWallet {
},
skipClassPublication: true,
skipInstancePublication: true,
wait: { timeout: 120 },
};

const receipt = await deployMethod.send(deployOpts).wait({ timeout: 120 });
const receipt = await deployMethod.send(deployOpts);

logger.info('Account deployed', receipt);

Expand Down
3 changes: 1 addition & 2 deletions boxes/boxes/vanilla/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ voteButton.addEventListener('click', async (e) => {
// Send tx
await votingContract.methods
.cast_vote(candidate)
.send({ from: connectedAccount })
.wait();
.send({ from: connectedAccount });

// Update tally
displayStatusMessage('Updating vote tally...');
Expand Down
32 changes: 18 additions & 14 deletions boxes/boxes/vanilla/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import {
type ContractInstanceWithAddress,
DeployMethod,
getContractInstanceFromInstantiationParams,
InteractionWaitOptions,
} from '@aztec/aztec.js/contracts';
import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee';
import { Fr } from '@aztec/aztec.js/fields';
import { PublicKeys } from '@aztec/aztec.js/keys';
import { createAztecNodeClient } from '@aztec/aztec.js/node';
import type { DeployAccountOptions, Wallet } from '@aztec/aztec.js/wallet';
import type {
DeployAccountOptions,
Wallet,
} from '@aztec/aztec.js/wallet';
import { type AztecNode } from '@aztec/aztec.js/node';
import { SPONSORED_FPC_SALT } from '@aztec/constants';
import { createStore } from '@aztec/kv-store/lmdb';
Expand Down Expand Up @@ -68,7 +72,7 @@ async function createAccount(wallet: TestWallet) {

const deployMethod = await accountManager.getDeployMethod();
const sponsoredPFCContract = await getSponsoredPFCContract();
const deployOpts: DeployAccountOptions = {
const deployOpts: DeployAccountOptions<InteractionWaitOptions> = {
from: AztecAddress.ZERO,
fee: {
paymentMethod: new SponsoredFeePaymentMethod(
Expand All @@ -77,8 +81,9 @@ async function createAccount(wallet: TestWallet) {
},
skipClassPublication: true,
skipInstancePublication: true,
wait: { timeout: 120 },
};
await deployMethod.send(deployOpts).wait({ timeout: 120 });
await deployMethod.send(deployOpts);
Comment thread
Thunkar marked this conversation as resolved.

return accountManager.address;
}
Expand Down Expand Up @@ -110,17 +115,16 @@ async function deployContract(wallet: Wallet, deployer: AztecAddress) {

const sponsoredPFCContract = await getSponsoredPFCContract();

await deployMethod
.send({
from: deployer,
contractAddressSalt: salt,
fee: {
paymentMethod: new SponsoredFeePaymentMethod(
sponsoredPFCContract.address
),
},
})
.wait({ timeout: 120 });
await deployMethod.send({
from: deployer,
contractAddressSalt: salt,
fee: {
paymentMethod: new SponsoredFeePaymentMethod(
sponsoredPFCContract.address
),
},
wait: { timeout: 120 },
});
await wallet.registerContract(contract, PrivateVotingContract.artifact);

return {
Expand Down
25 changes: 11 additions & 14 deletions boxes/boxes/vite/src/hooks/useContract.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useState } from "react";
import { deployerEnv } from "../config";
import { useState } from 'react';
import { deployerEnv } from '../config';

import { Contract } from "@aztec/aztec.js/contracts";
import { Fr } from "@aztec/aztec.js/fields";
import { toast } from "react-toastify";
import { Contract } from '@aztec/aztec.js/contracts';
import { Fr } from '@aztec/aztec.js/fields';
import { toast } from 'react-toastify';

export function useContract() {
const [wait, setWait] = useState(false);
Expand All @@ -17,22 +17,19 @@ export function useContract() {
const defaultAccountAddress = deployerEnv.getDefaultAccountAddress();
const salt = Fr.random();

const { BoxReactContract } = await import("../../artifacts/BoxReact");
const { BoxReactContract } = await import('../../artifacts/BoxReact');

const tx = await BoxReactContract.deploy(
wallet,
Fr.random(),
defaultAccountAddress,
).send({
const deploymentPromise = BoxReactContract.deploy(wallet, Fr.random(), defaultAccountAddress).send({
from: defaultAccountAddress,
contractAddressSalt: salt,
});
const contract = await toast.promise(tx.deployed(), {
pending: "Deploying contract...",

const contract = await toast.promise(deploymentPromise, {
pending: 'Deploying contract...',
success: {
render: ({ data }) => `Address: ${data.address}`,
},
error: "Error deploying contract",
error: 'Error deploying contract',
});

setContract(contract);
Expand Down
21 changes: 8 additions & 13 deletions boxes/boxes/vite/src/hooks/useNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react";
import { Contract } from "@aztec/aztec.js/contracts";
import { toast } from "react-toastify";
import { deployerEnv } from "../config";
import { useState } from 'react';
import { Contract } from '@aztec/aztec.js/contracts';
import { toast } from 'react-toastify';
import { deployerEnv } from '../config';

export function useNumber({ contract }: { contract: Contract }) {
const [wait, setWait] = useState(false);
Expand All @@ -21,23 +21,18 @@ export function useNumber({ contract }: { contract: Contract }) {
const setNumber = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();

const el = e.currentTarget.elements.namedItem(
"numberToSet",
) as HTMLInputElement;
const el = e.currentTarget.elements.namedItem('numberToSet') as HTMLInputElement;
if (el) {
setWait(true);

const value = BigInt(el.value);
const defaultAccountAddress = deployerEnv.getDefaultAccountAddress();
await toast.promise(
contract!.methods
.setNumber(value, defaultAccountAddress)
.send({ from: defaultAccountAddress })
.wait(),
contract!.methods.setNumber(value, defaultAccountAddress).send({ from: defaultAccountAddress }),
{
pending: "Setting number...",
pending: 'Setting number...',
success: `Number set to: ${value}`,
error: "Error setting number",
error: 'Error setting number',
},
);
setWait(false);
Expand Down
22 changes: 6 additions & 16 deletions docs/examples/ts/aztecjs_getting_started/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ const token = await TokenContract.deploy(
alice.address,
"TokenName",
"TKN",
18
)
.send({ from: alice.address })
.deployed();
18,
).send({ from: alice.address });
// docs:end:deploy

// docs:start:mint
await token.methods
.mint_to_private(alice.address, 100)
.send({ from: alice.address })
.wait();
.send({ from: alice.address });
// docs:end:mint

// docs:start:check_balances
Expand All @@ -45,28 +42,21 @@ console.log(`Bob's balance: ${bobBalance}`);
// docs:end:check_balances

// docs:start:transfer
await token.methods
.transfer(bob.address, 10)
.send({ from: alice.address })
.wait();
await token.methods.transfer(bob.address, 10).send({ from: alice.address });
bobBalance = await token.methods
.balance_of_private(bob.address)
.simulate({ from: bob.address });
console.log(`Bob's balance: ${bobBalance}`);
// docs:end:transfer

// docs:start:set_minter
await token.methods
.set_minter(bob.address, true)
.send({ from: alice.address })
.wait();
await token.methods.set_minter(bob.address, true).send({ from: alice.address });
// docs:end:set_minter

// docs:start:bob_mints
await token.methods
.mint_to_private(bob.address, 100)
.send({ from: bob.address })
.wait();
.send({ from: bob.address });
bobBalance = await token.methods
.balance_of_private(bob.address)
.simulate({ from: bob.address });
Expand Down
Loading
Loading