0

My objective is to create a path payment, to pay from one funded testnet account to another. A code snippet is below (Can't include the whole function, I guess because it exceeds stack exchange code snippet limit).

.addOperation(StellarSdk.Operation.pathPayment({
    source: sourcePublicKey,
    destination: receiverPublicKey,
    sendAsset: new StellarSdk.Asset.native(),
    sendMax: "500",
    destAsset: new StellarSdk.Asset("USD",receiverPublicKey),
    destAmount: "1",
  }))

I haven't specified a PATH, and my understanding is that Stellar will find the optimum route. However, I'm getting a transaction failure 'op_too_few_offers'.

Is this because I'm running on the testnet, and the stellar exchange is more "sparse" in terms of offers etc?

(Assumption of mine is that XLM to USD is probably a common case when developing/testing).

The line "sendAsset: new StellarSdk.Asset.native()" will (as I understand it), specify the source asset as XLM.

[Note - sourcePublicKey and receiverPublicKey are fine, I just cant show the whole block of code to illustrate where they are initialized]

2

The error op_too_few_offers is because there is no offer on the decentralized exchange for USD that were issued by your receiverPublicKey.

I think you have a misconception of assets on the stellar network. An asset is defined by a combination of the asset code and the issuing account ID. There is no single "USD" asset but various "USD-ISSUER1", "USD-ISSUER2",... on the network (where ISSUERX = stellar accountID, the second parameter of new StellarSdk.Asset() where you have used receiverPublicKey, which is most likely wrong because even if your receiver was also the asset issuer then by sending tokens back to the issuer the tokens would be burned). Anyone can issue as many USD as they want and naturally not all USD are trustworthy. You have to choose which USD issuer you want to trust+accept and then create a trustline before you are able to send/receive that tokens with your account. The various USD tokens from different issuers are not interoperable unless you exchange them trough offers or path payments.

For you to get started you should create your own asset by preparing these on testnet (pro tip: not manually but write a script because you might to do that again since testnet gets reset every 3 months):

  • Create four accounts on testnet (issuer, distributor, userSender, userReceiver)
  • Create a trustline each from userReceiver and from distributor for your USD-issuer asset
  • Pay some USD-issuer tokens from your issuer to your distributor (this is how tokens are generated)
  • Create an offer to exchange XLM <-> USD-issuer from your distributor
  • Now you can do a path payment from userSender:XLM (yeah, that's new StellarSdk.Asset.native()) to userReceiver:USD-issuer, which will use the offer from distributor to exchange

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.