Skip to content

Account.sendMoney() function failing. #1452

Open
@B35000

Description

Im trying to initiate a send money transaction in my basic web-wallet that sends some near from a funded address to a new address in a custom CRA javascript application, but the function for actually building, signing and submitting the transaction to the network is failing. My codebase looks like this:

const nearAPI = require("near-api-js");
const { connect, keyStores, utils, KeyPair } = nearAPI;
...

run_near_transaction = async (wallet, wallet2) => {
  const keyStore = new keyStores.InMemoryKeyStore();
  const keyPair = KeyPair.fromString(wallet.account.secretKey);
  await keyStore.setKey("mainnet", wallet.address, keyPair); //<-------set my account's keys in the keyStore

  const config = {
      networkId: "mainnet",
      nodeUrl: "https://1rpc.io/near",
      walletUrl: "https://1rpc.io/near",
      helperUrl: 'https://1rpc.io/near',
      keyStore: keyStore,
    };

   const near = await connect(config);
  ...

Im using the inMemoryKeyStore because im generating a wallet from a mnemonic. The wallet.account.secretKey is the secret key im using and the wallet.address is a valid near protocol address. The address im using is this: 1933b1fa96e6f84bcedf0ab46ccd2a224e92362c3a7c4478e2bd71b4fe83f699; it has about 0.25 Near as of the time of this writing, enough to be recognized by the network as a valid account.

  ...
  const amount = this.nearToYocto('0.1')
  const account = await near.account(wallet.address);
  try{
    var state = await account.state()
    console.log(state)
    const result = await account.sendMoney(wallet2.address, amount); //<---------- this call fails
    console.log("Transaction Result:", result);
  }catch(e){
    console.log(e)
  }
}

this.nearToYocto() converts a specified amount of Near into the base unit denominations and wallet2.address is a second new address i'm generating from another mnemonic. I query the state of the account to check if it exists in the network and it does; heres the response i'm getting from the await account.state() function call:

{
    "amount": "250000000000000000000000",
    "block_hash": "8B94eWwm1FjxjQnBAA7cpkh67anojwAPEpfoHUQ7HxRm",
    "block_height": 138969632,
    "code_hash": "11111111111111111111111111111111",
    "locked": "0",
    "storage_paid_at": 0,
    "storage_usage": 182
}

but when it attempts to execute the await account.sendMoney() function, it fails throwing this error:

TypedError: Can not sign transactions for account 1933b1fa96e6f84bcedf0ab46ccd2a224e92362c3a7c4478e2bd71b4fe83f699 on network mainnet, no matching key pair exists for this account
    at Account.signTransaction (account.cjs:50:1)
    at async account.cjs:72:1
    at async exponentialBackoff (exponential-backoff.cjs:8:1)
    at async Account.signAndSendTransaction (account.cjs:71:1)
    at async App.run_near_transaction (App.js:2680:1)

NPM version: 9.6.7, Node version: 18.17.1, the near-api-js version in my package.json: "near-api-js": "^5.0.1".

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status

      NEW❗

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions