Skip to content

Commit

Permalink
docs: update atlas links + inline scripts (#132)
Browse files Browse the repository at this point in the history
Updated [Atlas](https://atlaszk.com) documentation links and references
as per our internal upgrade of ZKsync within Atlas.

---------

Signed-off-by: Cliff Syner <[email protected]>
Co-authored-by: Antonio <[email protected]>
  • Loading branch information
alpinevm and uF4No authored Jul 1, 2024
1 parent dee59a2 commit a7ce7d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Atlas is a browser-based IDE with an integrated AI assistant that allows you to
directly from your browser. Click the button below to open the project in Atlas.

:u-button{ icon="i-heroicons-code-bracket" size="lg" color="primary" variant="solid" :trailing="false"
to="https://app.atlaszk.com/projects?template=https://github.com/ZKsync-Community-Hub/zksync-quickstart-atlas&open=/contracts/ZeekMessages.sol&chainId=%%zk_testnet_chain_id%%"
to="https://app.atlaszk.com/templates/33EAJkwrTKFaDJiEuy9Om?chainId=%%zk_testnet_chain_id%%&openFile=/contracts/ZeekSecretMessages.sol"
target="_blank" label="Open smart contract in Atlas"}

### Compile and deploy the contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Atlas is a browser-based IDE with an integrated AI assistant that allows you to
directly from your browser. Click the button below to open the project in Atlas.

:u-button{ icon="i-heroicons-code-bracket" size="lg" color="primary" variant="solid" :trailing="false"
to="https://app.atlaszk.com/projects?template=https://github.com/ZKsync-Community-Hub/zksync-quickstart-atlas&open=/contracts/TestToken.sol&chainId=%%zk_testnet_chain_id%%"
to="https://app.atlaszk.com/templates/33EAJkwrTKFaDJiEuy9Om?chainId=%%zk_testnet_chain_id%%&openFile=/contracts/TestToken.sol"
target="_blank" label="Open smart contract in Atlas"}

You can see the contract in the Atlas code editor. In the right sidebar,
Expand All @@ -71,43 +71,41 @@ Once compiled sign the transaction with your wallet and wait until its processed
In the `scripts` folder you can find the `mint-token.ts` script containing the following code:

```ts
import { AtlasEnvironment } from "atlas-ide";
import TokenArtifact from "../artifacts/TestToken";
import * as ethers from "ethers";
import { ethers } from "hardhat";

// Address of the ERC20 token contract
const TOKEN_CONTRACT_ADDRESS = ""
const TOKEN_CONTRACT_ADDRESS = "";
// Wallet that will receive tokens
const RECEIVER_WALLET = "";
const RECEIVER_WALLET = "";
// Amount of tokens to mint in ETH format, e.g. 1.23
const TOKEN_AMOUNT = "";
const TOKEN_AMOUNT = "";

export async function main (atlas: AtlasEnvironment) {
const provider = new ethers.providers.Web3Provider(atlas.provider);
const wallet = provider.getSigner();

// initialise token contract with address, abi and signer
const tokenContract= new ethers.Contract(
TOKEN_CONTRACT_ADDRESS,
TokenArtifact.TestToken.abi,
wallet
);
async function main() {
const Token = await ethers.getContractFactory("TestToken");
const tokenContract = Token.attach(TOKEN_CONTRACT_ADDRESS);

console.log("Minting tokens...");

const tx = await tokenContract.mint(
RECEIVER_WALLET,
ethers.utils.parseEther(TOKEN_AMOUNT)
ethers.parseEther(TOKEN_AMOUNT),
);
await tx.wait();


console.log("Success!");
console.log(`
The account ${RECEIVER_WALLET} now has
${await tokenContract.balanceOf(RECEIVER_WALLET)} tokens`
console.log(
`The account ${RECEIVER_WALLET} now has ${await tokenContract.balanceOf(
RECEIVER_WALLET,
)} tokens`,
);

}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
```

This scripts uses `ethers` to interact with the contract we’ve just deployed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Paymaster with Atlas
Click the following button to open the project in Atlas:

:u-button{ icon="i-heroicons-code-bracket" size="lg" color="primary" variant="solid" :trailing="false"
to="https://app.atlaszk.com/projects?template=https://github.com/ZKsync-Community-Hub/zksync-quickstart-atlas&open=/scripts/paymaster-transaction.ts&chainId=%%zk_testnet_chain_id%%"
to="https://app.atlaszk.com/templates/33EAJkwrTKFaDJiEuy9Om?chainId=%%zk_testnet_chain_id%%&openFile=/scripts/paymaster-transaction.ts"
target="_blank" label="Open script in Atlas"}

It’ll open the script to send a transaction via the paymaster. Let’s go through the most important parts:
Expand All @@ -16,8 +16,8 @@ It’ll open the script to send a transaction via the paymaster. Let’s go thro
// retrieve and print the current balance of the wallet
let ethBalance = await provider.getBalance(walletAddress)
let tokenBalance = await tokenContract.balanceOf(walletAddress)
console.log(`Account ${walletAddress} has ${ethers.utils.formatEther(ethBalance)} ETH`);
console.log(`Account ${walletAddress} has ${ethers.utils.formatUnits(tokenBalance, 18)} tokens`);
console.log(`Account ${walletAddress} has ${ethers.formatEther(ethBalance)} ETH`);
console.log(`Account ${walletAddress} has ${ethers.formatUnits(tokenBalance, 18)} tokens`);
```

In this part we’re retrieving the ETH and ERC20 token balances of the account. We’ll compare them after the transaction
Expand All @@ -31,20 +31,20 @@ const testnetPaymasterAddress = await zkProvider.getTestnetPaymasterAddress();

console.log(`Testnet paymaster address is ${testnetPaymasterAddress}`);

const gasPrice = await provider.getGasPrice();
const gasPrice = await zkProvider.getGasPrice();

// define paymaster parameters for gas estimation
const paramsForFeeEstimation = utils.getPaymasterParams(testnetPaymasterAddress, {
type: "ApprovalBased",
token: TOKEN_CONTRACT_ADDRESS,
// set minimalAllowance to 1 for estimation
minimalAllowance: ethers.BigNumber.from(1),
minimalAllowance: ethers.toBigInt(1),
// empty bytes as testnet paymaster does not use innerInput
innerInput: new Uint8Array(0),
});

// estimate gasLimit via paymaster
const gasLimit = await messagesContract.estimateGas.sendMessage(NEW_MESSAGE, {
const gasLimit = await messagesContract.sendMessage.estimateGas(NEW_MESSAGE, {
customData: {
gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
paymasterParams: paramsForFeeEstimation,
Expand Down Expand Up @@ -101,8 +101,8 @@ const fee = gasPrice * gasLimit;
```typescript
ethBalance = await provider.getBalance(walletAddress)
tokenBalance = await tokenContract.balanceOf(walletAddress)
console.log(`Account ${walletAddress} now has ${ethers.utils.formatEther(ethBalance)} ETH`);
console.log(`Account ${walletAddress} now has ${ethers.utils.formatUnits(tokenBalance, 18)} tokens`);
console.log(`Account ${walletAddress} now has ${ethers.formatEther(ethBalance)} ETH`);
console.log(`Account ${walletAddress} now has ${ethers.formatUnits(tokenBalance, 18)} tokens`);
```

Finally we retrieve and print the ETH and ERC20 balances to see how they’ve changed.
Expand Down

0 comments on commit a7ce7d6

Please sign in to comment.