Skip to content

[Bug] QuickStart script does not work #714

@QingyangKong

Description

@QingyangKong

🐛 Bug Description

Follow the instructions in quickstart and have the issue Resource not found by Address

How to reproduce

run npx ts-node src/quickstart.ts
run npm i @aptos-labs/ts-sdk
copy the sample code to quickstart.ts

/**
 * This example shows how to use the Aptos client to create accounts, fund them, and transfer between them.
 */
 
import { Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
 
const APTOS_COIN = "0x1::aptos_coin::AptosCoin";
const COIN_STORE = `0x1::coin::CoinStore<${APTOS_COIN}>`;
const ALICE_INITIAL_BALANCE = 100_000_000;
const BOB_INITIAL_BALANCE = 100;
const TRANSFER_AMOUNT = 100;
 
async function example() {
  console.log(
    "This example will create two accounts (Alice and Bob), fund them, and transfer between them.",
  );
 
  // Setup the client
  const config = new AptosConfig({ network: Network.DEVNET });
  const aptos = new Aptos(config);
 
  // Generate two account credentials
  // Each account has a private key, a public key, and an address
  const alice = Account.generate();
  const bob = Account.generate();
 
  console.log("=== Addresses ===\n");
  console.log(`Alice's address is: ${alice.accountAddress}`);
  console.log(`Bob's address is: ${bob.accountAddress}`);
 
  // Fund the accounts using a faucet
  console.log("\n=== Funding accounts ===\n");
 
  await aptos.fundAccount({
    accountAddress: alice.accountAddress,
    amount: ALICE_INITIAL_BALANCE,
  });
 
  await aptos.fundAccount({
    accountAddress: bob.accountAddress,
    amount: BOB_INITIAL_BALANCE,
  });
  console.log("Alice and Bob's accounts have been funded!");
 
  // Look up the newly funded account's balances
  console.log("\n=== Balances ===\n");
  const aliceAccountBalance = await aptos.getAccountResource({
    accountAddress: alice.accountAddress,
    resourceType: COIN_STORE,
  });
  const aliceBalance = Number(aliceAccountBalance.coin.value);
  console.log(`Alice's balance is: ${aliceBalance}`);
 
  const bobAccountBalance = await aptos.getAccountResource({
    accountAddress: bob.accountAddress,
    resourceType: COIN_STORE,
  });
  const bobBalance = Number(bobAccountBalance.coin.value);
  console.log(`Bob's balance is: ${bobBalance}`);
 
  // Send a transaction from Alice's account to Bob's account
  const txn = await aptos.transaction.build.simple({
    sender: alice.accountAddress,
    data: {
      // All transactions on Aptos are implemented via smart contracts.
      function: "0x1::aptos_account::transfer",
      functionArguments: [bob.accountAddress, 100],
    },
  });
 
  console.log("\n=== Transfer transaction ===\n");
  // Both signs and submits
  const committedTxn = await aptos.signAndSubmitTransaction({
    signer: alice,
    transaction: txn,
  });
  // Waits for Aptos to verify and execute the transaction
  const executedTransaction = await aptos.waitForTransaction({
    transactionHash: committedTxn.hash,
  });
  console.log("Transaction hash:", executedTransaction.hash);
 
  console.log("\n=== Balances after transfer ===\n");
  const newAliceAccountBalance = await aptos.getAccountResource({
    accountAddress: alice.accountAddress,
    resourceType: COIN_STORE,
  });
  const newAliceBalance = Number(newAliceAccountBalance.coin.value);
  console.log(`Alice's balance is: ${newAliceBalance}`);
 
  const newBobAccountBalance = await aptos.getAccountResource({
    accountAddress: bob.accountAddress,
    resourceType: COIN_STORE,
  });
  const newBobBalance = Number(newBobAccountBalance.coin.value);
  console.log(`Bob's balance is: ${newBobBalance}`);
 
  // Bob should have the transfer amount
  if (newBobBalance !== TRANSFER_AMOUNT + BOB_INITIAL_BALANCE)
    throw new Error("Bob's balance after transfer is incorrect");
 
  // Alice should have the remainder minus gas
  if (newAliceBalance >= ALICE_INITIAL_BALANCE - TRANSFER_AMOUNT)
    throw new Error("Alice's balance after transfer is incorrect");
}
 
example();

run npx ts-node src/quickstart.ts

Stack trace / error message

Error [AptosApiError]: Request to [Fullnode]: GET https://api.devnet.aptoslabs.com/v1/accounts/0xe03a3f2bf1f2b6d2438329c3a87b70d8c0e8c0e3020850ccfb375fd6b0cc795c/resource/0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin> (trace_id:ff757991a6e371f8d4e8a39b52a1d876) failed with: {"message":"Resource not found by Address(0xe03a3f2bf1f2b6d2438329c3a87b70d8c0e8c0e3020850ccfb375fd6b0cc795c), Struct tag(0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>) and Ledger version(164585426)","error_code":"resource_not_found","vm_error_code":null}
    at or (/Users/qingyangkong/environment/tutorials/aptos-learning/aptos_sdk_data_feed/node_modules/@aptos-labs/ts-sdk/src/core/crypto/keyless.ts:522:24)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Gi (/Users/qingyangkong/environment/tutorials/aptos-learning/aptos_sdk_data_feed/node_modules/@aptos-labs/ts-sdk/src/transactions/typeTag/parser.ts:359:43) {
  url: 'https://api.devnet.aptoslabs.com/v1/accounts/0xe03a3f2bf1f2b6d2438329c3a87b70d8c0e8c0e3020850ccfb375fd6b0cc795c/resource/0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>',
  status: 404,
  statusText: 'Not Found',
  data: {
    message: 'Resource not found by Address(0xe03a3f2bf1f2b6d2438329c3a87b70d8c0e8c0e3020850ccfb375fd6b0cc795c), Struct tag(0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>) and Ledger version(164585426)',
    error_code: 'resource_not_found',
    vm_error_code: null
  },
  request: {
    url: 'https://api.devnet.aptoslabs.com/v1',
    method: 'GET',
    originMethod: 'getResource',
    path: 'accounts/0xe03a3f2bf1f2b6d2438329c3a87b70d8c0e8c0e3020850ccfb375fd6b0cc795c/resource/0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>',
    contentType: undefined,
    acceptType: undefined,
    params: { ledger_version: undefined }
    overrides: { HEADERS: {} }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions