stellar / js-stellar-sdk

Main Stellar client library for the JavaScript language.
https://stellar.github.io/js-stellar-sdk/
Apache License 2.0
641 stars 312 forks source link

XDR Write Error - got 65536 bytes expected 4K #128

Closed KINKCreative closed 6 years ago

KINKCreative commented 6 years ago

The default asset issuing code from https://www.stellar.org/developers/guides/issuing-assets.html and any changes to it (e.g. custom asset name / different accounts) trigger this error:

initialize.js:60 Error! Error: XDR Write Error: Got 65536 bytes, expected 4
    at Opaque.write (http://localhost:3333/vendor.js:42782:17)
    at http://localhost:3333/vendor.js:43060:16
    at arrayEach (http://localhost:3333/vendor.js:47639:13)
    at http://localhost:3333/vendor.js:49695:13
    at Function.write (http://localhost:3333/vendor.js:43053:9)
    at http://localhost:3333/vendor.js:43663:35
    at arrayEach (http://localhost:3333/vendor.js:47639:13)
    at http://localhost:3333/vendor.js:49695:13
    at VarArray.write (http://localhost:3333/vendor.js:43662:9)
    at http://localhost:3333/vendor.js:43060:16
    at arrayEach (http://localhost:3333/vendor.js:47639:13)
    at http://localhost:3333/vendor.js:49695:13
    at Function.write (http://localhost:3333/vendor.js:43053:9)
    at Function.toXDR (http://localhost:3333/vendor.js:42682:10)
    at ChildStruct.toXDR (http://localhost:3333/vendor.js:42716:35)
    at Server.submitTransaction (http://localhost:3333/vendor.js:85383:70)
From previous event:
    at http://localhost:3333/app.js:984:47
    at initModule (http://localhost:3333/vendor.js:42:5)
    at require (http://localhost:3333/vendor.js:59:41)
    at http://localhost:3333/:29:11

Someone on Slack #dev put it into a flat file and the code supposedly works.

The setup is with require / as part of a ReactJS application although I also removed any references to React in the js code and got the same error.

Code:

var StellarSdk = require('stellar-sdk');
StellarSdk.Network.useTestNetwork();
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');

// Keys for accounts to issue and receive the new asset
var issuingKeys = StellarSdk.Keypair
  .fromSecret('SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4');
var receivingKeys = StellarSdk.Keypair
  .fromSecret('SDSAVCRE5JRAI7UFAVLE5IMIZRD6N6WOJUWKY4GFN34LOBEEUS4W2T2D');

// Create an object to represent the new asset
var astroDollar = new StellarSdk.Asset('AstroDollar', issuingKeys.publicKey());

// First, the receiving account must trust the asset
server.loadAccount(receivingKeys.publicKey())
  .then(function(receiver) {
    var transaction = new StellarSdk.TransactionBuilder(receiver)
      // The `changeTrust` operation creates (or alters) a trustline
      // The `limit` parameter below is optional
      .addOperation(StellarSdk.Operation.changeTrust({
        asset: astroDollar,
        limit: '1000'
      }))
      .build();
    transaction.sign(receivingKeys);
    return server.submitTransaction(transaction);
  })

  // Second, the issuing account actually sends a payment using the asset
  .then(function() {
    return server.loadAccount(issuingKeys.publicKey())
  })
  .then(function(issuer) {
    var transaction = new StellarSdk.TransactionBuilder(issuer)
      .addOperation(StellarSdk.Operation.payment({
        destination: receivingKeys.publicKey(),
        asset: astroDollar,
        amount: '10'
      }))
      .build();
    transaction.sign(issuingKeys);
    return server.submitTransaction(transaction);
  })
  .catch(function(error) {
    console.error('Error!', error);
  });
bartekn commented 6 years ago

I can't reproduce the bug with the code you pasted. Could you send more details about your environment? What's the version of node you're using? Are you using any bundler before running a code?

bartekn commented 6 years ago

No more info about this bug in a few months. Closing.