<p>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:</p>

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

<p>I signed and submitted this trustline.</p>

<p>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:</p>

<pre><code>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
    }
  }
};
</code></pre>

<p>Earlier, this was not working due to qualityIn and qualityOut being to 0.91 and 0.87</p>

CC BY-SA 3.0
2016-08-05T11:48:09.160Z
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
CC BY-SA 3.0
2016-07-06T06:54:11.560Z
2016-07-06T06:54:11.560Z
Abhishek Divekar
<p>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. </p>

<p>I assume the functionality for this is built into api.preparePayment(). So far, I am able to transfer XRP using code found in the <a href="https://github.com/ripple/ripple-lib/blob/develop/docs/samples/payment.js" rel="nofollow">payment example of ripple-lib</a>. The essence is:</p>

<pre><code>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(() =&gt; {
  console.log('Connected...');

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

<p>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? </p>

<p>My <code>trustline</code> object was:</p>

<pre><code>var trustline = {
  "currency": "USD",
  "counterparty": GATEWAY_ADDRESS, 
  "limit": "100",
  "qualityIn": 0.91,
  "qualityOut": 0.87,
  "ripplingDisabled": true,
  "frozen": false,
};
</code></pre>

<ripple><ripple-gateways><ripple-api>
RippleAPI how to issue IOUs using preparePayment
Abhishek Divekar
# RippleAPI how to issue IOUs using preparePayment

(Asked by: username_0 on 2016-07-05)

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,
};

**Tags:** ripple, ripple-gateways, ripple-api


---

## 1 answers

### Answer by username_0 on 2016-07-06. Score: 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

> **Comments:**
> **username_1**: 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.)  

---

