PixelBridge Core
  • What is PixelBridge Core?
  • ⚪PRODUCT
    • How does PixelBridge Core work?
      • Fees
      • Messaging protocols
      • PixelBridge Core contracts
      • Token value
      • Liquidity provision
    • PixelBridge Core guide
    • How to provide liquidity?
    • How to bridge with PixelBridge Core via mobile TronLink
    • Security audit
  • ⚪PixelBridge CORE SDK
    • Get started
    • Guides
      • General
        • Token info
        • Send
        • Swap
        • Paying fees with stables
      • EVM
        • Transfer
        • Allowance and approve
      • Solana
        • Transfer
        • Swap
      • Stellar
        • Transfer
      • Utilities
        • Amount and fee calculations
        • Transfer time
        • Extra gas limits
  • ⚪SOCIAL LINKS
    • Twtter
    • Telegram
    • Medium
  • ⚪PixelBridge ECOSYSTEM
    • PixelBridge Classic
    • PixelBridge BaaS
Powered by GitBook
On this page
  1. ⚪PixelBridge CORE SDK
  2. Guides
  3. Stellar

Transfer

Tokens and parameters are compiled in the same way as for other chains:

const sdk = new PixelBridgeCoreSdk(nodeRpcUrlsDefault);

const chainDetailsMap = await sdk.chainDetailsMap();
const sourceToken = chainDetailsMap[ChainSymbol.SRB].tokens.find((t) => t.symbol == "USDT");
const destinationToken = chainDetailsMap[ChainSymbol.ETH].tokens.find((t) => t.symbol == "USDT");
const amount = "2";
const sendParams: SendParams = {
  amount,
  fromAccountAddress: fromAddress,
  toAccountAddress: toAddress,
  sourceToken,
  destinationToken,
  messenger: Messenger.PixelBridge,
  extraGas: "1.15",
  extraGasFormat: AmountFormat.FLOAT,
  gasFeePaymentMethod: FeePaymentMethod.WITH_STABLECOIN,
};
const xdrTx: string = (await sdk.bridge.rawTxBuilder.send(sendParams)) as string;

Simulate the transaction before sending it. If some data is archived on Stellar, you have to restore it before sending the transaction. The simulation method can return a restore transaction, in this case, you have to send it first:

// SendTx
const srbKeypair = Keypair.fromSecret(privateKey);
const transaction = TransactionBuilder.fromXDR(xdrTx, mainnet.sorobanNetworkPassphrase);
transaction.sign(srbKeypair);
const signedTx = transaction.toXDR();

const restoreXdrTx = await sdk.utils.srb.simulateAndCheckRestoreTxRequiredSoroban(signedTx, fromAddress);
if (restoreXdrTx) {
  restoreXdrTx.sign(srbKeypair);
  const signedRestoreXdrTx = restoreXdrTx.toXDR();
  const sentRestoreXdrTx = await sdk.utils.srb.sendTransactionSoroban(signedRestoreXdrTx);
  const confirmRestoreXdrTx = await sdk.utils.srb.confirmTx(sentRestoreXdrTx.hash);
  if (confirmRestoreXdrTx.status === SorobanRpc.Api.GetTransactionStatus.NOT_FOUND) {
    console.log(
      `Waited for Restore transaction to complete, but it did not. ` +
        `Check the transaction status manually. ` +
        `Hash: ${sentRestoreXdrTx.hash}`
    );
  } else if (confirmRestoreXdrTx.status === SorobanRpc.Api.GetTransactionStatus.FAILED) {
    console.log(`Transaction Restore failed. Check the transaction manually.` + `Hash: ${sentRestoreXdrTx.hash}`);
  } else {
    console.log(`Transaction Restore Confirmed. Hash: ${sentRestoreXdrTx.hash}`);
  }
  //generate new tx with updated sequences
  const xdrTx2 = (await sdk.bridge.rawTxBuilder.send(sendParams)) as string;
  const transaction2 = TransactionBuilder.fromXDR(xdrTx2, mainnet.sorobanNetworkPassphrase);
  transaction2.sign(srbKeypair);
  signedTx = transaction2.toXDR();
}

Then you have to send the main transaction. Please note that if you send a restore transaction before, the transaction sequence will be changed, and you have to recompile it:

const sent = await sdk.utils.srb.sendTransactionSoroban(signedTx);
const confirm = await sdk.utils.srb.confirmTx(sent.hash);
if (confirm.status === SorobanRpc.Api.GetTransactionStatus.NOT_FOUND) {
  console.log(
    `Waited for transaction to complete, but it did not. ` +
      `Check the transaction status manually. ` +
      `Hash: ${sent.hash}`
  );
} else if (confirm.status === SorobanRpc.Api.GetTransactionStatus.FAILED) {
  console.log(`Transaction failed. Check the transaction manually.` + `Hash: ${sent.hash}`);
} else {
  console.log(`Transaction Confirmed. Hash: ${sent.hash}`);
}

Finally, if you make a transfer to Stellar, you have to ensure that you have trustlines for the destination token. Use the example below to check for the trustline/create it:

//TrustLine check and Set up for destinationToken if it is SRB
const destinationTokenSBR = sourceToken; // simulate destination is srb

const balanceLine = await sdk.utils.srb.getBalanceLine(fromAddress, destinationTokenSBR.tokenAddress);
console.log(`BalanceLine:`, balanceLine);
const notEnoughBalanceLine = !balanceLine || Big(balanceLine.balance).add(amount).gt(Big(balanceLine.limit));
if (notEnoughBalanceLine) {
  const xdrTx = await sdk.utils.srb.buildChangeTrustLineXdrTx({
    sender: fromAddress,
    tokenAddress: destinationTokenSBR.tokenAddress,
    // limit: "1000000",
  });

  //SignTx
  const keypair = StellarKeypair.fromSecret(privateKey);
  const transaction = StellarTransactionBuilder.fromXDR(xdrTx, mainnet.sorobanNetworkPassphrase);
  transaction.sign(keypair);
  const signedTrustLineTx = transaction.toXDR();

  const submit = await sdk.utils.srb.submitTransactionStellar(signedTrustLineTx);
  console.log("Submitted change trust tx. Hash:", submit.hash);
}
PreviousStellarNextUtilities

Last updated 12 months ago