If I want to create a trustline between my issuing account and new users accounts, how do I do this. I tried with this code:

const StellarSdk = require('stellar-sdk');
StellarSdk.Network.useTestNetwork(); // StellarSdk.Network.usePublicNetwork();
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org'); // const server = new StellarSdk.Server('https://horizon.stellar.org');

// an arbitary list of trusted assets
const ASSETS = {
    'TestToken': new StellarSdk.Asset('TestToken', 'G... *issuer account*'), //name, ISSUER ACC
    'XLM': StellarSdk.Asset.native()

// helper function to get desired asset object
const getAsset = (asset) => {
    if (ASSETS[asset]) return ASSETS[asset]
    return StellarSdk.Asset.native()

//create the distributor account keypair
const distributorKeypair = StellarSdk.Keypair.fromSecret('S... *Distrubutor Account Secret*') //DISTRIBUTOR ACCOUNT
//create the new account keypairs to use
var newAccountKeypair = StellarSdk.Keypair.random();
var newAccount = newAccountKeypair.publicKey(); // newAccount account address, taken from random keypair's public key
var newAccountSecret = newAccountKeypair.secret();

//load the new account to create trustline
.then(account => {

    // new transaction builder (convenience constructor grabs tx sequence number from account object)
    let builder = new StellarSdk.TransactionBuilder(account);

    //OPERATION 2: Change Trustline to trust the asset to be used on the platform.
            asset: asset: getAsset('TestToken'), //asset
            source: "G... *issuer account*" //issuer account

    // create the transaction XDR
    let transaction = builder.build();

    // sign the XDR

    // submit to the network. this returns a promise (resolves or rejects depending on the outcome of the transaction)

but got errors:

(node:17428) UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
    at createError (d:Stellar\node_modules\axios\lib\core\createError.js:16:15)
    at settle (d:\Stellar\node_modules\axios\lib\core\settle.js:18:12)
    at IncomingMessage.handleStreamEnd (d:\Stellar\node_modules\axios\lib\adapters\http.js:201:11)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:17428) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:17428) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can Anyone help me figure out what I am doing wrong. I got pretty much the same method of action to work for creating and funding the new account but this gives errors that I don't understand.

Any help is appreciated. Thank you.

  • You have asset: asset: Aug 3 at 19:37

3 Answers 3


server.loadAccount(newAccountKeypair.publicKey()) can't find your account on the ledger, because it's not on the ledger.

You need to create the account using createAccount before you can run any other operation on it.


In your previous question you posted the link to the SDK API documentation, pointing exactly at the Operation.changeTrust static method. So just follow the described method signature. It says that method accepts single argument - object with the following fields: asset of type Asset, optional limit as string, and optional source as string. So you should do the following:

const builder = new StellarSdk.TransactionBuilder(account);

        asset: new StellarSdk.Asset("TestToken", "G...*issuer account*")

const transaction = builder.build();

Looks like you use issuer as source in the changeTrust operation. This is incorrect. The source here is the account that trusts the issuer, whereas the issuer is in the asset the source trusts.

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.