-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e789c7
commit a5c5a25
Showing
27 changed files
with
468 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
TODO: | ||
The next step is to create some accounts. An in-depth explaining about accounts on aztec can be found [here](../../concepts/foundation/accounts/main.md). But creating an account on the Sandbox does 2 things: | ||
|
||
1. Deploys an account contract -- representing you -- allowing you to perform actions on the network (deploy contracts, call functions etc). | ||
2. Adds your encryption keys to the RPC Server allowing it to decrypt and manage your private state. | ||
|
||
Continue with adding the following to the `index.ts` file in our example: | ||
|
||
#include code Accounts | ||
```typescript title="Accounts" showLineNumbers | ||
////////////// CREATE SOME ACCOUNTS WITH SCHNORR SIGNERS ////////////// | ||
// Creates new accounts using an account contract that verifies schnorr signatures | ||
// Returns once the deployment transactions have settled | ||
const createSchnorrAccounts = async (numAccounts: number, aztecRpc: AztecRPC) => { | ||
const accountManagers = Array(numAccounts) | ||
.fill(0) | ||
.map(() => | ||
getSchnorrAccount( | ||
aztecRpc, | ||
GrumpkinScalar.random(), // encryption private key | ||
GrumpkinScalar.random(), // signing private key | ||
), | ||
); | ||
return await Promise.all( | ||
accountManagers.map(async x => { | ||
await x.waitDeploy({}); | ||
return x; | ||
}), | ||
); | ||
}; | ||
|
||
// Create 2 accounts and wallets to go with each | ||
logger(`Creating accounts using schnorr signers...`); | ||
const accounts = await createSchnorrAccounts(2, aztecRpc); | ||
|
||
////////////// VERIFY THE ACCOUNTS WERE CREATED SUCCESSFULLY ////////////// | ||
|
||
const [alice, bob] = (await Promise.all(accounts.map(x => x.getCompleteAddress()))).map(x => x.address); | ||
|
||
// Verify that the accounts were deployed | ||
const registeredAccounts = (await aztecRpc.getRegisteredAccounts()).map(x => x.address); | ||
for (const [account, name] of [ | ||
[alice, 'Alice'], | ||
[bob, 'Bob'], | ||
] as const) { | ||
if (registeredAccounts.find(acc => acc.equals(account))) { | ||
logger(`Created ${name}'s account at ${account.toShortString()}`); | ||
continue; | ||
} | ||
logger(`Failed to create account for ${name}!`); | ||
} | ||
``` | ||
|
||
|
||
Running `yarn start` should now output: | ||
|
||
``` | ||
token Aztec Sandbox Info { | ||
version: 1, | ||
chainId: 31337, | ||
rollupAddress: EthAddress { | ||
buffer: <Buffer cf 7e d3 ac ca 5a 46 7e 9e 70 4c 70 3e 8d 87 f6 34 fb 0f c9> | ||
}, | ||
client: '[email protected]', | ||
compatibleNargoVersion: '0.11.1-aztec.0' | ||
} | ||
token Creating accounts using schnorr signers... +3ms | ||
token Created Alice's account at 0x1509b252...0027 +10s | ||
token Created Bob's account at 0x031862e8...e7a3 +0ms | ||
``` | ||
That might seem like a lot to digest but it can be broken down into the following steps: | ||
1. We create 2 `Account` objects in Typescript. This object heavily abstracts away the mechanics of configuring and deploying an account contract and setting up a 'wallet' for signing transactions. If you aren't interested in building new types of account contracts or wallets then you don't need to be too concerned with it. In this example we have constructed account contracts and corresponding wallets that sign/verify transactions using schnorr signatures. | ||
2. We wait for the deployment of the 2 account contracts to complete. | ||
3. We retrieve the expected account addresses from the `Account` objects and ensure that they are present in the set of account addresses registered on the Sandbox. | ||
Note, we use the `getRegisteredAccounts` API to verify that the addresses computed as part of the | ||
account contract deployment have been successfully added to the Sandbox. | ||
If you were looking at your terminal that is running the Sandbox you should have seen a lot of activity. This is because the Sandbox will have simulated the deployment of both contracts, executed the private kernel circuit for each before submitted 2 transactions to the pool. The sequencer will have picked them up and inserted them into a rollup and executed the recursive rollup circuits before publishing the rollup to Anvil. Once this has completed, the rollup is retrieved and pulled down to the internal RPC Server so that any new account state can be decrypted. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.