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
'USDT': new StellarSdk.Asset('USDT', 'GCQTGZQQ5G4PTM2GL7CDIFKUBIPEC52BROAQIAPW53XBRJVN6ZJVTG6V'),
'MOBI' : new StellarSdk.Asset('MOBI', 'GA6HCMBLTZS5VYYBCATRBRZ3BZJMAFUDKYYF6AH6MVCMGWMRDNSWJPIH'),
'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
server.loadAccount(newAccountKeypair.publicKey())
.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.
builder.addOperation(
StellarSdk.Operation.changeTrust({
asset: asset: getAsset('TestToken'), //asset
source: "G... *issuer account*" //issuer account
})
)
// create the transaction XDR
let transaction = builder.build();
// sign the XDR
transaction.sign(newAccountKeypair);
// submit to the network. this returns a promise (resolves or rejects depending on the outcome of the transaction)
server.submitTransaction(transaction);
})
but got errors:
(node:17428) UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
warning.js:18
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)
warning.js:18
(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.
asset: asset: