0

UPDATE: I removed the quotes from BPTOKEN. That was a mistake. I had them removed in the real code but cut and pasted a change before this happened. It has been corrected and the error included. I also cant figure out how to keep the extras area from printing objects instead of human readable code.

I am using the JavascriptSDK. I just set up a Custom Asset with an issuing and distribution account (DISTRO1). I have changed trust and set a limit for the Distribution account using my new BPTOKENS well above 0. I did not pay the Distribution account any of my new BPTOKENS. It has a zero balance for my BPTOKENS.

I then set up a secondary Distribution account (DISTRO2). I changed the trust and set a limit for the DISTRO2 account well above 0. This time I paid the account 5000000 of my BPTOKENS.

I attempted to set up a payment from DISTRO2 account to DISTRO1 account with the zero balance. The transaction fails. Here is the code:

const fs = require('fs');
const StellarSdk = require('stellar-sdk');

const server = new StellarSdk.Server('https://horizon-testnet.stellar.org')
const source = StellarSdk.Keypair.fromSecret('SDDJHVW7TYJMFQ5QKPWQJY2Q5UWJLSC6Y77TVEFCZOHLJEMJKLHUAXQ5')

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

// DISTRO2/BASE Account - limit = 5000000
var PayerKeys = StellarSdk.Keypair
  .fromSecret('SDDJHVW7TYJMFQ5QKPWQJY2Q5UWJLSC6Y77TVEFCZOHLJEMJKLHUAXQ5');

// DISTRO1/Base Account - limit = 1000000
var ReceiverKeys = StellarSdk.Keypair
  .fromSecret('SBKKT7JUQFBWWX5AGA22QCWUXWZRY7PLWFFLKBIR3RE236JDPLHNMUY7');

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


var public = source.publicKey();


//////////////

StellarSdk.Network.useTestNetwork()

server.accounts()
        .accountId(source.publicKey())
        .call()
        .then(
                ({ sequence }) => {
                        const account = new StellarSdk.Account(source.publicKey(), sequence)
                        const transaction = new StellarSdk.TransactionBuilder(account, { fee: StellarSdk.BASE_FEE })

                        .addOperation(StellarSdk.Operation.payment(
                                {
                                        destination: "GADVTLHV5T7J2EZM5MCDBHZMK67Y3H573PCKAOGKE5Y54EEWPFZYWZXB",
                                        asset: BPTOKEN,
                                        // asset: StellarSdk.Asset.native(),
                                        amount: "1.50"  // 1000.50 XLM
                                }
                        ))
                        .setTimeout(30) //////////////////////////////////////////////////////////
                        .build()
                        transaction.sign(StellarSdk.Keypair.fromSecret(source.secret()))
                        return server.submitTransaction(transaction)
                }
        )



        .catch(function(error) {
                console.log('Error!', error);
        });

ERROR CODE FOLLOWS:

GCXIRXSJSG5HVX3ARXR6A7ZZI6EKQGDEQXKJBSHEVVFXV5RRWZVQSNW6
{ sequence: '2942469209587754' }
Error! { Error: Request failed with status code 400
    at createError (/var/www/stellarjs/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/var/www/stellarjs/node_modules/axios/lib/core/settle.js:18:12)
    at IncomingMessage.handleStreamEnd (/var/www/stellarjs/node_modules/axios/lib/adapters/http.js:201:11)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)
  config: 
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 60000,
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: -1,
     validateStatus: [Function: validateStatus],
     headers: 
      { Accept: 'application/json, text/plain, */*',
        'Content-Type': 'application/x-www-form-urlencoded',
        'X-Client-Name': 'js-stellar-sdk',
        'X-Client-Version': '0.15.0',
        'User-Agent': 'axios/0.18.0',
        'Content-Length': 367 },
     method: 'post',
     url: 'https://horizon-testnet.stellar.org/transactions',
     data: 'tx=AAAAAK6I3kmRunrfYI3j4H85R4ioGGSF1JDI5K1LevYxtmsJAAAAZAAKdCkAAAArAAAAAQAAAAAAAAAAAAAAAFy0tLUAAAAAAAAAAQAAAAAAAAABAAAAAAdZrPXs%2Fp0TLOsEMJ8sV7%2BNn7%2FbxKA4yidx3hCWeXOLAAAAAkJQVE9LRU4AAAAAAAAAAACr7YN1HCBOtXX3b7UZEO5tTsQy1Skb0a1tpZGtG1XlAQAAAAAA5OHAAAAAAAAAAAExtmsJAAAAQJDmr9wtDF4fsXer%2By93gu6FBg%2FF5ZRVCP8%2FZqjNCwFpIxybS%2Btr4mPf40KjXuEMWPIpESAOnqmf3h98EGZT5wk%3D' },
  request: 
   ClientRequest {
     domain: null,
     _events: 
      { socket: [Function],
        abort: [Function],
        aborted: [Function],
        error: [Function],
        timeout: [Function],
        prefinish: [Function: requestOnPrefinish] },
     _eventsCount: 6,
     _maxListeners: undefined,
     output: [],
     outputEncodings: [],
     outputCallbacks: [],
     outputSize: 0,
     writable: true,
     _last: true,
     upgrading: false,
     chunkedEncoding: false,
     shouldKeepAlive: false,
     useChunkedEncodingByDefault: true,
     sendDate: false,
     _removedConnection: false,
     _removedContLen: false,
     _removedTE: false,
     _contentLength: null,
     _hasBody: true,
     _trailer: '',
     finished: true,
     _headerSent: true,
     socket: 
      TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: true,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        _SNICallback: null,
        servername: 'horizon-testnet.stellar.org',
        npnProtocol: undefined,
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object],
        _eventsCount: 9,
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: 'horizon-testnet.stellar.org',
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 648,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: [Object],
        _requestCert: true,
        _rejectUnauthorized: true,
        parser: null,
        _httpMessage: [Circular],
        [Symbol(asyncId)]: 32,
        [Symbol(bytesRead)]: 0 },
     connection: 
      TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: true,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        _SNICallback: null,
        servername: 'horizon-testnet.stellar.org',
        npnProtocol: undefined,
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object],
        _eventsCount: 9,
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: 'horizon-testnet.stellar.org',
        _readableState: [Object],
        readable: true,
        domain: null,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 648,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: [Object],
        _requestCert: true,
        _rejectUnauthorized: true,
        parser: null,
        _httpMessage: [Circular],
        [Symbol(asyncId)]: 32,
        [Symbol(bytesRead)]: 0 },
     _header: 'POST /transactions HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/x-www-form-urlencoded\r\nX-Client-Name: js-stellar-sdk\r\nX-Client-Version: 0.15.0\r\nUser-Agent: axios/0.18.0\r\nContent-Length: 367\r\nHost: horizon-testnet.stellar.org\r\nConnection: close\r\n\r\n',
     _onPendingData: [Function: noopPendingOutput],
     agent: 
      Agent {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: [Object],
        requests: {},
        sockets: [Object],
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        maxCachedSessions: 100,
        _sessionCache: [Object] },
     socketPath: undefined,
     timeout: undefined,
     method: 'POST',
     path: '/transactions',
     _ended: true,
     res: 
      IncomingMessage {
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        socket: [Object],
        connection: [Object],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        headers: [Object],
        rawHeaders: [Array],
        trailers: {},
        rawTrailers: [],
        upgrade: false,
        url: '',
        method: null,
        statusCode: 400,
        statusMessage: 'Bad Request',
        client: [Object],
        _consuming: true,
        _dumped: false,
        req: [Circular],
        responseUrl: 'https://horizon-testnet.stellar.org/transactions',
        redirects: [],
        read: [Function] },
     aborted: undefined,
     timeoutCb: null,
     upgradeOrConnect: false,
     parser: null,
     maxHeadersCount: null,
     _redirectable: 
      Writable {
        _writableState: [Object],
        writable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        _options: [Object],
        _ended: true,
        _ending: true,
        _redirectCount: 0,
        _redirects: [],
        _requestBodyLength: 367,
        _requestBodyBuffers: [],
        _onNativeResponse: [Function],
        _currentRequest: [Circular],
        _currentUrl: 'https://horizon-testnet.stellar.org/transactions' },
     [Symbol(outHeadersKey)]: 
      { accept: [Array],
        'content-type': [Array],
        'x-client-name': [Array],
        'x-client-version': [Array],
        'user-agent': [Array],
        'content-length': [Array],
        host: [Array] } },
  response: 
   { status: 400,
     statusText: 'Bad Request',
     headers: 
      { 'cache-control': 'no-cache, no-store, max-age=0',
        'content-type': 'application/problem+json; charset=utf-8',
        date: 'Mon, 15 Apr 2019 16:43:09 GMT',
        vary: 'Origin',
        'x-ratelimit-limit': '101',
        'x-ratelimit-remaining': '100',
        'x-ratelimit-reset': '1',
        'content-length': '960',
        connection: 'Close' },
     config: 
      { adapter: [Function: httpAdapter],
        transformRequest: [Object],
        transformResponse: [Object],
        timeout: 60000,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        validateStatus: [Function: validateStatus],
        headers: [Object],
        method: 'post',
        url: 'https://horizon-testnet.stellar.org/transactions',
        data: 'tx=AAAAAK6I3kmRunrfYI3j4H85R4ioGGSF1JDI5K1LevYxtmsJAAAAZAAKdCkAAAArAAAAAQAAAAAAAAAAAAAAAFy0tLUAAAAAAAAAAQAAAAAAAAABAAAAAAdZrPXs%2Fp0TLOsEMJ8sV7%2BNn7%2FbxKA4yidx3hCWeXOLAAAAAkJQVE9LRU4AAAAAAAAAAACr7YN1HCBOtXX3b7UZEO5tTsQy1Skb0a1tpZGtG1XlAQAAAAAA5OHAAAAAAAAAAAExtmsJAAAAQJDmr9wtDF4fsXer%2By93gu6FBg%2FF5ZRVCP8%2FZqjNCwFpIxybS%2Btr4mPf40KjXuEMWPIpESAOnqmf3h98EGZT5wk%3D' },
     request: 
      ClientRequest {
        domain: null,
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        upgrading: false,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: null,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [Object],
        connection: [Object],
        _header: 'POST /transactions HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/x-www-form-urlencoded\r\nX-Client-Name: js-stellar-sdk\r\nX-Client-Version: 0.15.0\r\nUser-Agent: axios/0.18.0\r\nContent-Length: 367\r\nHost: horizon-testnet.stellar.org\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Object],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/transactions',
        _ended: true,
        res: [Object],
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        _redirectable: [Object],
        [Symbol(outHeadersKey)]: [Object] },
     data: 
      { type: 'https://stellar.org/horizon-errors/transaction_failed',
        title: 'Transaction Failed',
        status: 400,
        detail: 'The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details.  Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html',
        extras: [Object] } } }

Question 1: The documentation on the Stellar website for Issuing Custom Assets payments (https://www.stellar.org/developers/guides/issuing-assets.html), goes through the entire process of changing trust, limits and other steps that seem like initial setup steps vs. a simple payment transaction. Does a simple payment transaction between two normal or distro accounts need the entire change of trust, limit set and other steps just to exchange assets?

Question 2: If the receiving account has its trust changed to accept BPTOKENS but has a zero balance of said tokens, will the transaction fail if an account with BPTOKENS attempts to send BPTOKENS to the receiving account?

Question 3: Are there other areas that I missed or programming errors I made above?

  • 2
    Could you add the error code? Would help us narrow it down. – Carl Vitullo Apr 10 at 13:50
  • It sounds like you have several questions. It would be easier to answer if you asked them separately. – ire_and_curses Apr 10 at 15:49
  • Remove the quotes, you want the asset object not a string in asset: 'BPTOKEN', – sui Apr 10 at 17:35
  • Who in the world down voted me for asking a question? Silly... Anyway, question was updated. – lvto2000 Apr 15 at 16:50
0

Answer 1: Every account that wants to accept/send a given token needs to first create a trustline for that asset once.

Answer 2: There are various possible failures like: asset is auth_required but the account is not authorized; payment amount exceeds the trust line limit; exceeds senders funds; invalid signatures; invalid trustlines; ...

However you will always get an according error code.

Answer 3)

  • The relevant information for transaction failures is hidden in error.response.data.extras, so it would be more helpful to console.log('Error!', error.response.data.extras);.

  • I've executed the raw transaction and it fails with op_no_trust, which means that the recipient does not have a trust line for that asset.

  • Indeed, the sender has a BPTOKEN trustline, the payment is a BPTOKEN payment, the recipient does not have a BPTOKEN but a BPTOKENS trustline instead. It's just a typo...

  • Thanks, I had figured it out last night but this definitely helps with presenting the error in a more readable way. – lvto2000 Apr 18 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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