Skip to main content
deleted 8 characters in body
Source Link
cesarm
  • 1.5k
  • 7
  • 20
server.offers('accounts', distributor.publicKey).call().then(function (offerResult) {
    console.log( **offerResultofferResult.records**records );
})  
server.offers('accounts', distributor.publicKey).call().then(function (offerResult) {
    console.log( **offerResult**offerResult );
})  
server.offers('accounts', distributor.publicKey).call().then(function (offerResult) {
    console.log( **offerResult.records** );
})  
server.offers('accounts', distributor.publicKey).call().then(function (offerResult) {
    console.log( **offerResult** );
})  
server.offers('accounts', distributor.publicKey).call().then(function (offerResult) {
    console.log( offerResult.records );
})  
server.offers('accounts', distributor.publicKey).call().then(function (offerResult) {
    console.log( offerResult );
})  
deleted 335 characters in body
Source Link
cesarm
  • 1.5k
  • 7
  • 20

I tried with substituting your "distributor"think it is a feature with account1NodeJS. They don't go deep to reveal every detail down an object.

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

 
var request = require('request');
var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Serveroffers('https://horizon-testnet.stellar'accounts', distributor.org'publicKey);
StellarSdk.Network.useTestNetworkcall();

//account1
pub1='GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'
sec1='SB44SZ5IQCK72ELARVZ53BLSPO4NFCKH7H6ZBVGIFZ47CWLD5O2ADCOD'
kp1=StellarSdk.Keypair.fromSecretthen(sec1)

//account2
pub2='GDNICVTW44YSI7BD6XB6GKPGCO6H367XT3JUFXG3XAFW46SOVKCBMPAI'
sec2='SDIC6OCFXYLEBCJQIEDN5LN2KNVW4VZYY6FEGTIQ5CCSU7KLCPHRGIH4'
kp2=StellarSdk.Keypair.fromSecretfunction (sec2offerResult)

var distributor=new Object    //just create Obj
distributor.publicKey=pub1
distributorKeyPair=kp1
{
var MCoin = new StellarSdkconsole.Assetlog('MCoin', pub1);
var XLM = StellarSdk.Asset**offerResult.native(records** );
 
server.loadAccount(distributor.publicKey).then(function(account}){
   

gives

> [ { _links: { varself: transaction[Object], =offer_maker: new[Object] StellarSdk.TransactionBuilder(account)},
     id: 234710,
    paging_token: '234710',
    seller: .addOperation(StellarSdk.Operation.manageOffer({'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT',
      selling:
     { asset_type: 'credit_alphanum12',
       sellingasset_code: MCoin 'MCoin',
       asset_issuer: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT' },
    buying: { asset_type: 'native' },
    buyingamount: XLM'200.0000000',
      price_r: { n: 2, d: 1 },
    price: '2.0000000',
   amount self: '200'[Function],
     offer_maker: [Function] },
  { _links: { self: [Object], offer_maker: [Object] },
    priceid: 2235067,
    paging_token: '235067',
    seller: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT',
    selling:
     { offerIdasset_type: 0'credit_alphanum12',
       asset_code: 'MCoin',
       asset_issuer: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT' })),
       buying: { asset_type: 'native' },
    amount: '200.build();0000000',
     price_r: { n: transaction.sign(distributorKeyPair);
2, d: 1 },
    price: //console.log(transaction.toEnvelope()'2.toXDR('base64'));
0000000',
       self: server.submitTransaction(transaction)[Function],
        offer_maker: [Function] } ]

WHEREAS

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

gives

{ records:
   [ { console.log('\n_links: Success!')[Object],
           id: })234710,
           paging_token: .catch(function(err){'234710',
          seller: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT',
     console.log('An error hasselling: occured');[Object],
       buying: [Object],
       amount: console'200.log(err);0000000',
            })

   price_r: }).catch(function(e){[Object],
       price: console'2.log(e);0000000',
    })

No problem spotted. Maybe could you verify if your distributor.publicKey gives a string of publickey & distributorKeyPair is an account object?

> distributorKeyPair
Keypair {
  typeself: 'ed25519'[Function],
  _secretSeed: <Buffer 79 c9 67 a8 80 95 fdoffer_maker: 11[Function] 60},
 8d 73 dd 85 72{ 7b_links: b8[Object],
 d2 89 47 f9 fd 90 d4id: c8235067,
 2e 79 f1 59 63 eb b4paging_token: 01>'235067',
  _secretKey: <Buffer 79 c9 67 a8 80 95 fd 11 60 8dseller: 73'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT',
 dd 85 72 7b b8 d2 89selling: 47[Object],
 f9 fd 90 d4 c8 2e 79buying: f1[Object],
 59 63 eb b4 01 82 29amount: 95'200.0000000',
 d1 d1 89 2d a5 1d 92price_r: 85[Object],
 89 0d ff cc 50 1e ebprice: ..'2. >0000000',
  _publicKey: <Buffer 82 29 95 d1 d1 89 2d a5 1d 92 85 89 0d ff cc 50 1eself: eb[Function],
 76 85 f3 d8 0b a5 b5offer_maker: e4[Function] ad} 14],
 8c 2bnext: 16[Function: 9a>next],
  publicKeyprev: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'[Function: }

>
>
>prev] distributor.publicKey
'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'}

p.s. I am using NodeJS v7. What version are you using btw?

I tried with substituting your "distributor" with account1:

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

//account1
pub1='GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'
sec1='SB44SZ5IQCK72ELARVZ53BLSPO4NFCKH7H6ZBVGIFZ47CWLD5O2ADCOD'
kp1=StellarSdk.Keypair.fromSecret(sec1)

//account2
pub2='GDNICVTW44YSI7BD6XB6GKPGCO6H367XT3JUFXG3XAFW46SOVKCBMPAI'
sec2='SDIC6OCFXYLEBCJQIEDN5LN2KNVW4VZYY6FEGTIQ5CCSU7KLCPHRGIH4'
kp2=StellarSdk.Keypair.fromSecret(sec2)

var distributor=new Object    //just create Obj
distributor.publicKey=pub1
distributorKeyPair=kp1

var MCoin = new StellarSdk.Asset('MCoin', pub1);
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(transactionResult);
                console.log('\n Success!')
            })
            .catch(function(err){
                console.log('An error has occured');
                console.log(err);
            })

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

No problem spotted. Maybe could you verify if your distributor.publicKey gives a string of publickey & distributorKeyPair is an account object?

> distributorKeyPair
Keypair {
  type: 'ed25519',
  _secretSeed: <Buffer 79 c9 67 a8 80 95 fd 11 60 8d 73 dd 85 72 7b b8 d2 89 47 f9 fd 90 d4 c8 2e 79 f1 59 63 eb b4 01>,
  _secretKey: <Buffer 79 c9 67 a8 80 95 fd 11 60 8d 73 dd 85 72 7b b8 d2 89 47 f9 fd 90 d4 c8 2e 79 f1 59 63 eb b4 01 82 29 95 d1 d1 89 2d a5 1d 92 85 89 0d ff cc 50 1e eb ... >,
  _publicKey: <Buffer 82 29 95 d1 d1 89 2d a5 1d 92 85 89 0d ff cc 50 1e eb 76 85 f3 d8 0b a5 b5 e4 ad 14 8c 2b 16 9a>,
  publicKey: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT' }

>
>
> distributor.publicKey
'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'

p.s. I am using NodeJS v7. What version are you using btw?

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] }
added 45 characters in body
Source Link
cesarm
  • 1.5k
  • 7
  • 20
var request = require('request');
var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
StellarSdk.Network.useTestNetwork();

//account1
pub1='GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'
sec1='SB44SZ5IQCK72ELARVZ53BLSPO4NFCKH7H6ZBVGIFZ47CWLD5O2ADCOD'
kp1=StellarSdk.Keypair.fromSecret(sec1)

//account2
pub2='GDNICVTW44YSI7BD6XB6GKPGCO6H367XT3JUFXG3XAFW46SOVKCBMPAI'
sec2='SDIC6OCFXYLEBCJQIEDN5LN2KNVW4VZYY6FEGTIQ5CCSU7KLCPHRGIH4'
kp2=StellarSdk.Keypair.fromSecret(sec2)

var distributor=new Object    //just create Obj
distributor.publicKey=pub1
distributorKeyPair=kp1

var MCoin = new StellarSdk.Asset('MCoin', pub1);
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(transactionResult);
                console.log('\n Success!')
            })
            .catch(function(err){
                console.log('An error has occured');
                console.log(err);
            })

    }).catch(function(e){
        console.log(e);
    })
var request = require('request');
var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
StellarSdk.Network.useTestNetwork();

//account1
pub1='GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'
sec1='SB44SZ5IQCK72ELARVZ53BLSPO4NFCKH7H6ZBVGIFZ47CWLD5O2ADCOD'
kp1=StellarSdk.Keypair.fromSecret(sec1)

//account2
pub2='GDNICVTW44YSI7BD6XB6GKPGCO6H367XT3JUFXG3XAFW46SOVKCBMPAI'
sec2='SDIC6OCFXYLEBCJQIEDN5LN2KNVW4VZYY6FEGTIQ5CCSU7KLCPHRGIH4'
kp2=StellarSdk.Keypair.fromSecret(sec2)

distributor.publicKey=pub1
distributorKeyPair=kp1

var MCoin = new StellarSdk.Asset('MCoin', pub1);
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(transactionResult);
                console.log('\n Success!')
            })
            .catch(function(err){
                console.log('An error has occured');
                console.log(err);
            })

    }).catch(function(e){
        console.log(e);
    })
var request = require('request');
var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
StellarSdk.Network.useTestNetwork();

//account1
pub1='GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'
sec1='SB44SZ5IQCK72ELARVZ53BLSPO4NFCKH7H6ZBVGIFZ47CWLD5O2ADCOD'
kp1=StellarSdk.Keypair.fromSecret(sec1)

//account2
pub2='GDNICVTW44YSI7BD6XB6GKPGCO6H367XT3JUFXG3XAFW46SOVKCBMPAI'
sec2='SDIC6OCFXYLEBCJQIEDN5LN2KNVW4VZYY6FEGTIQ5CCSU7KLCPHRGIH4'
kp2=StellarSdk.Keypair.fromSecret(sec2)

var distributor=new Object    //just create Obj
distributor.publicKey=pub1
distributorKeyPair=kp1

var MCoin = new StellarSdk.Asset('MCoin', pub1);
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(transactionResult);
                console.log('\n Success!')
            })
            .catch(function(err){
                console.log('An error has occured');
                console.log(err);
            })

    }).catch(function(e){
        console.log(e);
    })
Source Link
cesarm
  • 1.5k
  • 7
  • 20
Loading