Aztec.js is a library that provides APIs for managing accounts and interacting with contracts on the Aztec network.
Before starting installation, make sure that Node.js or Yarn is installed.
Start by installing the aztec.js pacakge from npm:
yarn add @aztec/aztec.js
Create a new file named main.js at the project directory:
touch main.js
Start by importing aztec.js library:
import { Contract } from '@aztec/aztec.js';Before diving into the code, see contract artifacts on the docs.
const contract = await Contract.deploy(wallet, MyContractArtifact, [...consructorArgs]).send().deployed();
console.log(`Contract deployed at ${contract.address}`);const contract = await Contract.at(contractAddress, MyContractArtifact, wallet);
const tx = await contract.methods.transfer(amount, recipientAddress).send().wait();
console.log(`Transferred ${amount} to ${recipientAddress} on block ${tx.blockNumber}`);const contract = await Contract.at(contractAddress, MyContractArtifact, wallet);
const balance = await contract.methods.get_balance(wallet.getAddress()).view();
console.log(`Account balance is ${balance}`);