0

I have a problem when trying to sign transactions in monero, using the monerojs library.

This is my code:

async function signAndSendTransaction(toAddress, amount) {

    let wallet = await monerojs.createWalletFull({
      networkType: MoneroNetworkType.TESTNET,
      password: "MoneroRoot",
      mnemonic: "after laptop autumn fixate plus boxes eavesdrop acumen bogeys hectare asylum mammal memoir addicted rebel austere bite lifestyle adapt morsel cousin tinted weekday awesome bite",
      serverUri: "http://127.0.0.1:28081",
    });

    const syncResult = await wallet.sync();
    console.log('Sync progress:', syncResult)
    
    const txConfig = new monerojs.MoneroTxConfig();
    txConfig.setAccountIndex(0); // Indice dell'account da cui inviare la transazione
    txConfig.setAddress(toAddress); // Indirizzo di destinazione
    txConfig.setAmount((ATOMICUNIT_PER_XMR*amount).toString());

    const txSet = await wallet.createTx(txConfig);

    await wallet.signTxs(txSet.getHash());

    let daemon = await monerojs.connectToDaemonRpc({
      uri: "http://127.0.0.1:28081",
    });
    const txHashes = await daemon.submitTxSet(txSet);
    console.log("Transazione inviata con hash:", txHashes[0]);
  }

it gives me this error when signing the transaction (signTxs()):

MoneroError: cannot load unsigned_txset

Is there some process I'm skipping? Online errors of this type with the monerojs library I can't find them.

1 Answer 1

0

There's a full example in the documentation of the 3rd party library you're using:

https://github.com/monero-ecosystem/monero-javascript/blob/master/docs/developer_guide/view_only_offline.md

8
  • Can you tell me why it combines code execution with the use of an offline wallet??
    – AlexCav
    Jun 25 at 20:35
  • The primary use case of signing an unsigned transaction is to do so with an offline wallet. The example is just showing the various commands (for both online and offline) aspects.
    – jtgrassie
    Jun 26 at 0:05
  • But, for example here: // export key images from offline wallet let keyImages = await offlineWallet.exportKeyImages(); // import key images to view-only wallet await viewOnlyWallet.importKeyImages(keyImages); The keyImages of offline-wallets is used by the online wallet. Some parameters are used by the online wallet. Since I want to use an online wallet, is it necessary to do what is done here?
    – AlexCav
    Jun 26 at 8:06
  • "Since I want to use an online wallet" then you don't need to sign separately at all. Just use createTx which will sign for you. github.com/monero-ecosystem/monero-javascript/blob/master/docs/…
    – jtgrassie
    Jun 26 at 12:25
  • Sending and digning txs with createTx() returns me this error: Error during coin exchange: MoneroError: Internal error: can't get block by hash. Hash = 2d08b9e89bfc9813d717211201da207ae21ac9b3caf4d507132ede2267fa41b2. I have this code: const tx = await wallet.createTx({ accountIndex: 0, address: toAddress, amount: amountInAtomic.toString() }); let fee = tx.getFee(); let hash = await wallet.relayTx(tx); or using: const tx = await wallet.createTxs({ accountIndex: 0, address: toAddress, amount: amountInAtomic.toString(), relay:true });
    – AlexCav
    Aug 17 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.