# Create Trust Line and Send Currency Using JavaScript This example shows how to: 1. Create a trust line between two accounts. 2. Send issued currency between accounts. 3. Display account balances for all currencies. [](/assets/mt-send-currency-1-empty-form-info.6d95e080d536a53431e15e88bcb4f313a304f1131a806d91c0dc8de6475443fa.ac57e6ef.png) You can download the [Payment Modular Tutorials](/assets/payment-modular-tutorials.a27fd32656123cc667fdfb8949e8c79c60732fc4da4448548774646ed28d5e69.bb35afea.zip) from the source repository for this website. Without the Payment modular tutorials, you will not be able to try the examples that follow. ## Usage Open the Send Currency test harness and get accounts: 1. Open `send-currency.html` in a browser. 2. Get test accounts. 1. If you copied the gathered information from another tutorial: 1. Paste the gathered information to the **Result** field. 2. Click **Distribute Account Info**. 2. If you have an existing account seed: 1. Paste the account seed to the **Account 1 Seed** or **Account 2 Seed** field. 2. Click **Get Account 1 from Seed** or **Get Account 2 from Seed**. 3. If you do not have existing accounts: 1. Click **Get New Account 1**. 2. Click **Get New Account 2**. [](/assets/mt-send-currency-2-distribute-accounts.5e4fb4d4e92d15d91c663edad9d82dfafe4ca3b79c54b9515124e1f605211a8f.ac57e6ef.png) If you want an account to be able to transfer issued currency to accounts other than the issuer, the issuer account must be configured to allow rippling. See *Issuer* in the [Configuring Accounts](/ja/docs/concepts/accounts/configuring-accounts#issuer) topic. Accounts can always transfer currency tokens back to the original issuer. ## Create Trust Line In order to trade standard tokens, you must first establish a trust line from the receiving account to the issuing account. To create a trust line between accounts: 1. Click **Account 2** to populate the uneditable fields in the form. 2. Enter a [currency code](https://www.iban.com/currency-codes) in the **Currency Code** field. 3. Enter the maximum transfer limit in the **Amount** field. 4. Copy and paste the **Account 1 Address** value to the **Issuer** field. 5. Click **Create Trust Line**. [](/assets/mt-send-currency-3-create-trustline.931b5e38838dc275a5a6b01628261a7c482283854d0cd036cf4648befdf12162.ac57e6ef.png) ## Send an Issued Currency Token To transfer an issued currency token, once you have created a trust line: 1. Click **Account 1**. 2. Enter the **Currency Code**. 3. Copy and paste the **Account 1 Address** to the **Issuer** field. 4. Enter the **Amount** of issued currency to send. 5. Copy and paste the **Account 2 Address** to the **Destination** field. 6. Click **Send Currency**. [](/assets/mt-send-currency-4-send-currency.431a222190611d74b0f03d23cc0556270e965c1c24481be2b84b5f6b7f32de57.ac57e6ef.png) ## Get the Current Token Balance To see the balances for all issued tokens for an account. 1. Click **Account 1** or **Account 2**. 2. Click **Get Token Balance**. The balance for an issuing account is shown as an obligation. [](/assets/mt-send-currency-5-issuer-token-balance.ea98b5a240a79ff061417ca6f959f71807a95510e55afa3753d0c1a3f54c95d6.ac57e6ef.png) The balance for a holder account is shown as an asset. [](/assets/mt-send-currency-6-holder-token-balance.7e88a664ce970edbe8615f0561422d1cc2ea6b385048668f2e114cbcb4d608a6.ac57e6ef.png) # Code Walkthrough You can download the [Payment Modular Tutorials](/assets/payment-modular-tutorials.a27fd32656123cc667fdfb8949e8c79c60732fc4da4448548774646ed28d5e69.bb35afea.zip) from the source repository for this website. ## send-currency.js There are two asynchronous functions in the send-currency.js file that build on the base module to add new behavior for sending issued currency between accounts. ### Create Trust Line A trust line enables two accounts to trade a defined currency up to a set limit. This gives the participants assurance that any exchanges are between known entities at agreed upon maximum amounts. Connect to the XRPL server. ```javascript async function createTrustLine() { const net = getNet() const client = new xrpl.Client(net) await client.connect() let results = "\nConnected. Creating trust line.\n" resultField.value = results ``` Create a `TrustSet` transaction, passing the currency code, issuer account, and the total value the holder is willing to accept. ```javascript try { const wallet = xrpl.Wallet.fromSeed(accountSeedField.value) const trustSet_tx = { "TransactionType": "TrustSet", "Account": accountAddressField.value, "LimitAmount": { "currency": currencyField.value, "issuer": issuerField.value, "value": amountField.value } } ``` Autofill the remaining default transaction parameters. ```javascript const ts_prepared = await client.autofill(trustSet_tx) ``` Sign and send the transaction to the XRPL server, then wait for the results. ```javascript const ts_signed = wallet.sign(ts_prepared) resultField.value = results const ts_result = await client.submitAndWait(ts_signed.tx_blob) ``` Report the results of the transaction. ```javascript if (ts_result.result.meta.TransactionResult == "tesSUCCESS") { results += '\n===Trust line established between account \n' + accountAddressField.value + ' \n and account\n' + issuerField.value + '.' resultField.value = results } else { results += `\n===Transaction failed: ${ts_result.result.meta.TransactionResult}` resultField.value = results } } ``` Catch and report any errors, then disconnect from the XRP Ledger. ```javascript catch (error) { console.error('===Error creating trust line:', error); results += `\n===Error: ${error.message}\n` resultField.value = results throw error; // Re-throw the error to be handled by the caller } finally { // Disconnect from the client await client.disconnect(); } } //End of createTrustline() ``` ### sendCurrency() This transaction actually sends a transaction that changes balances on both sides of the trust line. Connect to the XRP Ledger and get the account wallet. ```javascript async function sendCurrency() { let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '....' resultField.value = results await client.connect() results += '\nConnected.' resultField.value = results ``` Create a payment transaction to the destination account, specifying the amount using the currency, value, and issuer. ```javascript try { const wallet = xrpl.Wallet.fromSeed(accountSeedField.value) const send_currency_tx = { "TransactionType": "Payment", "Account": wallet.address, "Amount": { "currency": currencyField.value, "value": amountField.value, "issuer": issuerField.value }, "Destination": destinationField.value } ``` Autofill the remaining default transaction parameters. ```javascript const pay_prepared = await client.autofill(send_currency_tx) ``` Sign and send the prepared payment transaction to the XRP Ledger, then await and report the results. ```javascript const pay_signed = wallet.sign(pay_prepared) results += `\n\n===Sending ${amountField.value} ${currencyField.value} to ${destinationField.value} ...` resultField.value = results const pay_result = await client.submitAndWait(pay_signed.tx_blob) if (pay_result.result.meta.TransactionResult == "tesSUCCESS") { results += '\n===Transaction succeeded.' resultField.value = results } else { results += `\n===Transaction failed: ${pay_result.result.meta.TransactionResult}` resultField.value = results xrpBalanceField.value = (await client.getXrpBalance(wallet.address)) } } ``` Update the XRP value field to reflect the transaction fee. ```javascript catch (error) { console.error('Error sending transaction:', error); results += `\nError: ${error.message}\n` resultField.value = results throw error; // Re-throw the error to be handled by the caller } finally { // Disconnect from the client await client.disconnect(); } } // end of sendCurrency() ``` ## send-currency.html Update the form to support the new functions. ```html