Skip to content

Commit

Permalink
lasse's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed Aug 22, 2023
1 parent e0de173 commit 174757d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
29 changes: 20 additions & 9 deletions docs/docs/dev_docs/contracts/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Once you have [compiled](./compiling.md) your contracts you can proceed to deploying them using the aztec-cli or using aztec.js which is a Typescript client to interact with the sandbox.

## Prerequisites
- aztec-cli installed (go to [CLI main section](./main.md) for installation instructions)
- aztec-cli installed (go to [CLI main section](../cli/main.md) for installation instructions)
- contract artifacts ready (go to [Compiling contracts section](../contracts/compiling.md) for instructions on how to compile contracts)
- aztec-sandbox running (go to [Sandbox section](../sandbox/main.md) for instructions on how to install and run the sandbox)

Expand All @@ -25,18 +25,24 @@ aztec-cli deploy /path/to/contract/abi.json
</TabItem>
<TabItem value="js" label="Aztec.js">

Pre-requisite - Generate type-safe typescript classes for your contract when compiling:
```bash
aztec-cli compile /path/to/example_contract -ts /path/to/your/ts/files
Pre-requisite - Generate type-safe typescript classes for your contract when compiling using the `@aztec/noir-compiler` package. You can install the package by running `npm install @aztec/noir-compiler`.

```ts
import { readFileSync, writeFileSync } from 'fs';
import { compileUsingNargo, generateTypescriptContractInterface} from '@aztec/noir-compiler';

const compiled: ContractAbi[] = await compileUsingNargo(projectPathToContractFolder);
const abiImportPath = "../target/Example.json";
writeFileSync(tsInterfaceDestFilePath, generateTypescriptContractInterface(compiled[0], abiImportPath));
```
This would create a typescript file like `Example.ts` in the path specified. More details in the [compiling page](./compiling.md)

Now you can import to easily deploy and use the class.
Now you can import it to easily deploy and interact with the contract.
```ts
import { ExampleContract } from './Example.js';

const tx = ExampleContract.deploy(aztecRpc).send();
await tx.isMined({ interval: 0.5 });
await tx.wait({ interval: 0.5 });
const receipt = await tx.getReceipt();
const exampleContract = await ExampleContract.at(receipt.contractAddress!, myWallet);
```
Expand Down Expand Up @@ -98,6 +104,11 @@ aztec-cli register-recipient --address 0x147392a39e593189902458f4303bc6e0a39128c
<TabItem value="js" label="Aztec.js">

```ts
const aztecAddress = AztecAddress.fromString("0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529");
const publicKey = Point.fromString("0x26e193aef4f83c70651485b5526c6d01a36d763223ab24efd1f9ff91b394ac0c20ad99d0ef669dc0dde8d5f5996c63105de8e15c2c87d8260b9e6f02f72af622");
const partialAddress = Fr.fromString("0x200e9a6c2d2e8352012e51c6637659713d336405c29386c7c4ac56779ab54fa7");

const completeAddress = CompleteAddress.create(aztecAddress, publicKey, partialKey);
await aztecRpc.registerRecipient(completeAddress);
```

Expand Down Expand Up @@ -127,15 +138,15 @@ aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f43
// PrivateTokenContract is the TS interface that is automatically generated when compiling the contract with the `-ts` flag.
const initialBalance = 1000n;
const owner = AztecAddress.from("0x147392a39e593189902458f4303bc6e0a39128c5a1c1612f76527a162d36d529");
contract = await PrivateTokenContract.deploy(wallet, initialBalance, owner).send().deployed();
const contract = await PrivateTokenContract.deploy(wallet, initialBalance, owner).send().deployed();
logger(`Contract deployed at ${contract.address}`);
```

</TabItem>
</Tabs>

If everything went as expected you should see the following output (with a different address):
> Contract deployed at 0x151de6120ae6628129ee852c5fc7bcbc8531055f76d4347cdc86003bbea96906
> Contract deployed at `0x151de6120ae6628129ee852c5fc7bcbc8531055f76d4347cdc86003bbea96906`
If we pass the salt as an argument:

Expand All @@ -150,7 +161,7 @@ aztec-cli deploy PrivateTokenContractAbi --args 1000 0x147392a39e593189902458f43
<TabItem value="js" label="Aztec.js">

```ts
contract = await PrivateTokenContract.deploy(wallet, initialBalance, owner).send({ contractAddressSalt: Fr.fromString("0x123") }).deployed();
const contract = await PrivateTokenContract.deploy(wallet, initialBalance, owner).send({ contractAddressSalt: Fr.fromString("0x123") }).deployed();
```

</TabItem>
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/aztec.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import { ContractDeployer } from '@aztec/aztec.js';

const deployer = new ContractDeployer(contractAbi, aztecRpcServer);
const tx = deployer.deploy(constructorArgs[0], constructorArgs[1]).send();
await tx.isMined();
console.log('Contract deployed!');

const receipt = await tx.getReceipt();
console.log(`Contract address: ${receipt.contractAddress}`);
// wait for tx to be mined
const receipt = await tx.wait();
console.log(`Contract deployed at ${receipt.contractAddress}`);
```

#### Send a transaction
Expand All @@ -25,9 +23,11 @@ import { Contract } from '@aztec/aztec.js';

const contract = await Contract.at(contractAddress, contractAbi, aztecRpcServer);
const tx = contract.methods
.transfer(amount, recipientAddress))
.transfer(amount, recipientAddress)
.send({ origin: senderAddress });
await tx.isMined();

// wait for tx to be mined
await tx.wait();
console.log(`Transferred ${amount} to ${recipientAddress}!`);
```

Expand Down

0 comments on commit 174757d

Please sign in to comment.