Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs for sandbox usage #1477

Merged
merged 18 commits into from
Aug 10, 2023
Merged

Docs for sandbox usage #1477

merged 18 commits into from
Aug 10, 2023

Conversation

PhilWindle
Copy link
Collaborator

Some docs for sandbox retrieval/usage.

Checklist:

Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge.

  • If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag.
  • I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code.
  • Every change is related to the PR description.
  • I have linked this pull request to relevant issues (if any exist).

@PhilWindle PhilWindle marked this pull request as ready for review August 9, 2023 15:45
@PhilWindle PhilWindle changed the title Pw/sandbox docs Docs for sandbox usage Aug 9, 2023
Copy link
Collaborator

@spalladino spalladino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I left a bunch of suggestions, but nothing that would go against merging the PR.

docs/docs/dev_docs/sandbox/main.md Outdated Show resolved Hide resolved
docs/docs/dev_docs/sandbox/main.md Outdated Show resolved Hide resolved
docs/docs/dev_docs/sandbox/main.md Outdated Show resolved Hide resolved
docs/docs/dev_docs/sandbox/main.md Outdated Show resolved Hide resolved
docs/docs/dev_docs/sandbox/main.md Outdated Show resolved Hide resolved
That's it! We have successfully deployed a private token contract to an instance of the Aztec network and mined private state-transitioning transactions. We have also queried the resulting state all via the interfaces provided by the contract.

## Accounts and Keys
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section feels a bit out of place. Maybe it makes sense to run the whole flow with just one wallet, so we can showcase the addPublicKeyAndPartialAddress usage as part of it, rather than explaining it separately in this section? We'll lose the ability to query Bob's balance, but I think that's not too bad. It will also make the account setup code a lot easier to follow, since we can remove the loops, Promise.all, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of felt the same about that section. The reason I used 2 accounts is that without it you can't see the results of the transfer, i.e. Bob's balance.

It's a compromise really. In a private transaction you can only see one side of it but that doesn't make a very good demo!

Copy link
Collaborator

@spalladino spalladino Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but that doesn't make a very good demo

I disagree - I think it's a great demo for a private-first chain! Otherwise this demo is exactly the same as a regular public ERC20. The twist where you cannot see what happened in the recipient's account is important IMO.

Comment on lines +82 to +86
const tokenContractTx = PrivateTokenContract.deploy(
aztecRpc,
initialSupply, // the initial supply
alice // the owner of the initial supply
).send();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass in the wallet instead of the aztecRpc, you can call deployed() to get the instance. Note that this only makes sense if we adapt this flow to go with a single wallet.

Comment on lines +103 to +110
const viewUnencryptedLogs = async () => {
const lastBlock = await aztecRpc.getBlockNum();
logger(`Retrieving unencrypted logs for block ${lastBlock}`);
const logs = await aztecRpc.getUnencryptedLogs(lastBlock, 1);
const unrolledLogs = L2BlockL2Logs.unrollLogs(logs);
const asciiLogs = unrolledLogs.map((log) => log.toString("ascii"));
logger(`Emitted logs: `, asciiLogs);
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this should be moved to an util within aztec.js. Not for this PR, of course.

Comment on lines +132 to +140
logger(
`Alice's balance ${await tokenContractAlice.methods
.getBalance(alice)
.view()}`
);
// Check Bob's balance
logger(
`Bob's balance ${await tokenContractBob.methods.getBalance(bob).view()}`
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't really need to use the different tokenContractAlice/tokenContractBob for checking the different balances, since the RPC has access to the encrypted notes of both.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, I just thought it read a bit better that Alice checks her balance with her instance and Bob checks his with his.

Comment on lines 151 to 155
const transferTx = tokenContractAlice.methods
.transfer(transferQuantity, alice, bob)
.send();
// Now send the transaction to the network and wait for it to settle
await transferTx.wait();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const transferTx = tokenContractAlice.methods
.transfer(transferQuantity, alice, bob)
.send();
// Now send the transaction to the network and wait for it to settle
await transferTx.wait();
await tokenContractAlice.methods
.transfer(transferQuantity, alice, bob)
.send()
.wait();

WDYT? Feels more succinct, but it's a matter of personal style.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a fan of concise syntax when it doesn't worsen readability and it's very readable here so I would go with the change.

@PhilWindle PhilWindle enabled auto-merge (squash) August 10, 2023 13:30
@PhilWindle PhilWindle merged commit a09124a into master Aug 10, 2023
@PhilWindle PhilWindle deleted the pw/sandbox-docs branch August 10, 2023 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants