1

I created an asset (MCoin) on Stellar test-net. I made a sell-offer of 200 MCoin in exchange for XLM and then an offer of buying 200 MCoin for XLM.

But ther orders didn't match.

Here is the script I used to make an offer:

var MCoin = new StellarSdk.Asset('MCoin', 'GCKRPJXPGNHBPMRCXEX4MDH532BN5RLUJJOMVACA3CB7E2LWSTKTB5U2');
var XLM = StellarSdk.Asset.native();
server.loadAccount(distributor.publicKey)
    .then(function(account){
        var transaction = new StellarSdk.TransactionBuilder(account)
                .addOperation(StellarSdk.Operation.manageOffer({
                    selling: MCoin ,
                    buying: XLM,
                    amount : '200',
                    price: 2,
                    offerId: 0,
                }))
                .build();
        transaction.sign(distributorKeyPair);
        //console.log(transaction.toEnvelope().toXDR('base64'));

        server.submitTransaction(transaction)
            .then(function(transactionResult){
                //console.log(JSOn.stringify(transactionResult));
                console.log('\n Success!')
            })
            .catch(function(err){
                console.log('An error has occured');
                console.log(err);
            })

    })
    .catch(function(e){
        console.log(e);
    })

When I checked the offers from the accounts, I could see selling and buying was [Object]. The response when I checked for offers is:

{ records: 
   [ { _links: [Object],
       id: 221373,
       paging_token: '221373',
       seller: 'GB3K552PTUQB26X4LUNGPO7FN5GZGQAO2PXMKPCJ5A45ZJISANHFOHPR',
       selling: [Object],
       buying: [Object],
       amount: '200.0000000',
       price_r: [Object],
       price: '2.0000000',
       self: [Function],
       offer_maker: [Function] },
     { _links: [Object],
       id: 221566,
       paging_token: '221566',
       seller: 'GB3K552PTUQB26X4LUNGPO7FN5GZGQAO2PXMKPCJ5A45ZJISANHFOHPR',
       selling: [Object],
       buying: [Object],
       amount: '200.0000000',
       price_r: [Object],
       price: '2.0000000',
       self: [Function],
       offer_maker: [Function] } ],
  next: [Function: next],
  prev: [Function: prev] }

Can anyone guide on what am I missing?

1

I think it is a feature with NodeJS. They don't go deep to reveal every detail down an object.

Note the difference at console.log: offerResult.records VS offerResult


server.offers('accounts', distributor.publicKey).call().then(function (offerResult) {
    console.log( offerResult.records );
})  

gives

> [ { _links: { self: [Object], offer_maker: [Object] },
    id: 234710,
    paging_token: '234710',
    seller: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT',
    selling:
     { asset_type: 'credit_alphanum12',
       asset_code: 'MCoin',
       asset_issuer: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT' },
    buying: { asset_type: 'native' },
    amount: '200.0000000',
    price_r: { n: 2, d: 1 },
    price: '2.0000000',
    self: [Function],
    offer_maker: [Function] },
  { _links: { self: [Object], offer_maker: [Object] },
    id: 235067,
    paging_token: '235067',
    seller: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT',
    selling:
     { asset_type: 'credit_alphanum12',
       asset_code: 'MCoin',
       asset_issuer: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT' },
    buying: { asset_type: 'native' },
    amount: '200.0000000',
    price_r: { n: 2, d: 1 },
    price: '2.0000000',
    self: [Function],
    offer_maker: [Function] } ]

WHEREAS

server.offers('accounts', distributor.publicKey).call().then(function (offerResult) {
    console.log( offerResult );
})  

gives

{ records:
   [ { _links: [Object],
       id: 234710,
       paging_token: '234710',
       seller: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT',
       selling: [Object],
       buying: [Object],
       amount: '200.0000000',
       price_r: [Object],
       price: '2.0000000',
       self: [Function],
       offer_maker: [Function] },
     { _links: [Object],
       id: 235067,
       paging_token: '235067',
       seller: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT',
       selling: [Object],
       buying: [Object],
       amount: '200.0000000',
       price_r: [Object],
       price: '2.0000000',
       self: [Function],
       offer_maker: [Function] } ],
  next: [Function: next],
  prev: [Function: prev] }

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.