Creating Accounts

Now, we are ready to create the accounts. We will create two accounts here: one is the minter of the NFT, and the other is the account that will receive the newly minted NFT.

Accounts in Realloop can be created by either doing a deposit from Ethereum or by transferring funds from an existing Realloop account to the desired address.

import { Provider, Wallet as RlWallet, getDefaultProvider } from '@alonfalsing/realloop';
import { BigNumberish, ethers, Wallet } from 'ethers';

/* Connect to a local deployment */
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');

/* L1 wallets with enough balances */
const wallets = [
  // 0xa61464658AfeAf65CccaaFD3a512b69A83B77618
  'ac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3',
  // 0x0D43eB5B8a47bA8900d84AA36656c92024e9772e
  'd293c684d884d56f8d6abd64fc76757d3664904e309a0645baf8522ab6366d9e'
].map((k) => new Wallet(k).connect(provider));

async function deposit(wallet: Wallet, provider: Provider, amount: BigNumberish) {
  const w = await RlWallet.fromEthSigner(wallet, provider);
  const op = await w.depositToSyncFromEthereum({
    depositTo: w.address(),
    token: 'ETH',
    amount
  });
  const receipt = await op.awaitReceipt();
  console.log(JSON.stringify(receipt));
}

/* Top-level await doesn't work */
(async function () {
  const provider = await getDefaultProvider('localhost');
  for (const w of wallets) {
    await deposit(w, provider, '2000000000000000000');
  }
})();

We can check the account balances via getAccountState().

(async function () {
  const provider = await getDefaultProvider('localhost');
  for (const wallet of wallets) {
    const w = await RlWallet.fromEthSigner(wallet, provider);
    const s = await w.getAccountState();
    console.log(JSON.stringify(s));
  }
})();

Last updated