Joshua Edicha
Joshua Edicha

Reputation: 1

Why is Stellar SDK throwing [Object object] not a memo when memo is added when building transaction?

I'm trying to add a memo when generating a wallet on the Stellar network but the SDK keeps throwing this XDR write error.

Error stack trace:

TypeError: XDR Write Error: [object Object] is not a Memo
    at Function.write (webpack://WalletSDK/node_modules/@stellar/js-xdr/src/union.js:85:1)
    at Function.write (webpack://WalletSDK/node_modules/@stellar/js-xdr/src/struct.js:31:1)
    at Function.write (webpack://WalletSDK/node_modules/@stellar/js-xdr/src/union.js:88:1)
    at Function.write (webpack://WalletSDK/node_modules/@stellar/js-xdr/src/struct.js:31:1)
    at Function.toXDR (webpack://WalletSDK/node_modules/@stellar/js-xdr/src/xdr-type.js:57:1)
    at ChildStruct.toXDR (webpack://WalletSDK/node_modules/@stellar/js-xdr/src/xdr-type.js:12:1)
    at Transaction.signatureBase (webpack://WalletSDK/node_modules/@stellar/stellar-base/lib/transaction.js:293:1)
    at Transaction.hash (webpack://WalletSDK/node_modules/@stellar/stellar-base/lib/transaction_base.js:224:1)
    at Transaction.sign (webpack://WalletSDK/node_modules/@stellar/stellar-base/lib/transaction_base.js:88:1)
    at SigningKeypair.__webpack_modules__../src/walletSdk/Horizon/Account.ts.exports.SigningKeypair.SigningKeypair.sign (webpack://WalletSDK/src/walletSdk/Horizon/Account.ts:64:1)

Code:

    const createTxn = txBuilder
      .createAccount(createdAccountKeyPair)
      .setMemo(new Memo(MemoText, 'test-memo'))
      .build();

    const signed = sponsorSigningKeyPair.sign(createTxn);

These are the imports

import { Memo, xdr, MemoText } from '@stellar/stellar-sdk';
import {
  StellarConfiguration,
  Wallet,
  Keypair,
  AccountKeypair,
  IssuedAssetId,
  PublicKeypair,
  SigningKeypair,
  NativeAssetId,
} from '@stellar/typescript-wallet-sdk';

Versions:

    "@stellar/stellar-sdk": "^12.1.0",
    "@stellar/typescript-wallet-sdk": "^1.7.0",

This is my input:

    const createTxn = txBuilder
      .createAccount(createdAccountKeyPair)
      .setMemo(new Memo(MemoText, 'test-memo'))
      .build();

    const signed = sponsorSigningKeyPair.sign(createTxn);

Upvotes: 0

Views: 33

Answers (2)

Chidiebere Ezeokwelume
Chidiebere Ezeokwelume

Reputation: 139

If setMemo doesn't work, you could try addMemo ie

const createTxn = txBuilder
  .createAccount(createdAccountKeyPair)
  .addMemo(new Memo(MemoText, 'test-memo'))
  .build();

Upvotes: 0

Peter B
Peter B

Reputation: 24280

It should be done like this:

setMemo(new Memo("text", "Memo string"))

You are using MemoText as the first parameter, which is wrong, it should be a string according to the docs.

When the error message is constructed, it seems to do MemoText.toString() which causes [Object object] to be printed.

Upvotes: 0

Related Questions