0

I'm trying out the API, and I've set up one 'user' account, and one 'gateway' account. The only difference between the two is that the user has extended a trustline to the gateway account. I would now like to issue USD IOUs from the gateway to the user account.

I assume the functionality for this is built into api.preparePayment(). So far, I am able to transfer XRP using code found in the payment example of ripple-lib. The essence is:

const address = SENDER_ADDRESS;
const secret = SENDER_SECRET;

const payment = {
  source: {
    address: address,
    maxAmount: {
      value: '0.01',
      currency: 'XRP'
    }
  },
  destination: {
    address: RECEIVER_ADDRESS,
    amount: {
      value: '0.01',
      currency: 'XRP'
    }
  }
};


api.connect().then(() => {
  console.log('Connected...');

  return api.preparePayment(address, payment, instructions).then(prepared => {
    console.log('Payment transaction prepared...');
    const {signedTransaction} = api.sign(prepared.txJSON, secret);
    console.log('Payment transaction signed...');
    api.submit(signedTransaction);
  });

A few lines of code are missing but this is the basic structure. It works when I make either the Gateway or the user the sender, and the other the receiver. How should I modify it so that I can issue USD IOUs from the Gateway to the user?

My trustline object was:

var trustline = {
  "currency": "USD",
  "counterparty": GATEWAY_ADDRESS, 
  "limit": "100",
  "qualityIn": 0.91,
  "qualityOut": 0.87,
  "ripplingDisabled": true,
  "frozen": false,
};
1

Okay I figured it out: first, I set up a trustline from USER_ADDR to GATEWAY_ADDR for 1000 EUR. I made sure that the qualityIn and qualityOut were set to 0, the default value:

var trustline = {
  "currency": "EUR",
  "counterparty": GATEWAY_ADDR, 
  "limit": "1000",
  "ripplingDisabled": true,
  "frozen": false,
  "memos": [
    {
      "type": "test2",
      "format": "plain/text",
      "data": "texted data2"
    }
  ]
};

I signed and submitted this trustline.

I then used the following payment object to create an IOU for 50 EUR from the gateway to the user, indicating that the user had deposited 50 EUR with the gateway outside the Ripple system:

const payment = {
  source: {
    address: GATEWAY_ADDR,
    maxAmount: {
      currency: 'EUR',
      value: '50',
      counterparty: GATEWAY_ADDR
    }
  },
  destination: {
    address: USER_ADDR,
    amount: {
      currency: 'EUR',
      value: '50',
      counterparty: GATEWAY_ADDR
    }
  }
};

Earlier, this was not working due to qualityIn and qualityOut being to 0.91 and 0.87

  • Since you set the max amount to 50 EUR, the payment will only work if the cost to deliver 50 EUR is 50 EUR or less. If the recipient doesn't value the gateway's IOUs at face value, then it will cost the gateway more the 50 EUR to give the customer 50 EUR. (Ripple only requires issuers to value their own IOUs at face value. You can devalute other people's IOUs.) – David Schwartz Aug 5 '16 at 11:48

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.