This is my code:
var sourceSecretKey = 'REDACTED';
var sourceKeypair = StellarSdk.Keypair.fromSecret(sourceSecretKey);
var sourcePublicKey = sourceKeypair.publicKey();
var server = new StellarSdk.Server('https://horizon.stellar.org');
StellarSdk.Network.usePublicNetwork();
server.loadAccount(sourcePublicKey)
.then(function(account) {
var transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE
})
// Add a manageOffer operation
.addOperation(StellarSdk.Operation.manageBuyOffer({
selling: new StellarSdk.Asset.native(),
buying: new StellarSdk.Asset('ABC', 'GDFBWP6GYJE7PMA4HVLLSPG6346Z67XAME7C2WJIUIA5HGJEJWFWIBPI'),
amount: '0.001',
price: '15.6250000',
offerId: '0'
}))
.addMemo(StellarSdk.Memo.text('Hello'))
.setTimeout(180)
.build();
transaction.sign(sourceKeypair);
console.log(transaction.toEnvelope().toXDR('base64'));
server.submitTransaction(transaction)
.then(function(transactionResult) {
console.log(JSON.stringify(transactionResult, null, 2));
console.log('\nSuccess! View the transaction at: ');
console.log(transactionResult._links.transaction.href);
})
.catch(function(err) {
console.log('An error has occured:');
console.log(err);
});
})
.catch(function(e) {
console.error(e);
});
On submit, it shows an error:
TypeError: buyAmount argument must be of type String, represent a positive number and have at most 7 digits after the decimal
at Function.manageBuyOffer (stellar-sdk.js:43384)
at [.addOperation(StellarSdk.Operation.manageBuyOffer({]
I changed manageBuyOffer
to manageSellOffer
. It goes through, but the order book for the pair is not updated to reflect this offer. I tried doing the same transaction on stellarx.com
, and the transaction went through and the order got reflected in the order book.
I tried another transaction, this time switching the pairs. The amount was "1"
and the price "0.0540000"
. I got an error:
Error: Request failed with status code 400
at createError (stellar-sdk.js:27374)
at settle (stellar-sdk.js:46113)
at XMLHttpRequest.handleLoad (stellar-sdk.js:27236)
I am using the JavaScript SDK and running in the browser.
I did the same transaction on stellarx.com
, and the transaction went through as expected, and the order got reflected in the order book.
I wonder where all these errors are coming from.