Actions

getAccount
const account = getAccount();

export type Account = {
  triaName: string | null;
  evm: {
    address: string;
  };
};
disconnect
await disconnect();
signMessage
signMessage(
  calldata: SignMessageParams,
  dappDetails?: dappDetails,
  authUrl: string = triaAuthUrl,
  environment: ENV = 'mainnet'
): Promise<StringDataResponse>;

type SignMessageParams = {
  message: string; // eg. Sign in with Tria
  chainName: string; // eg. POLYGON
};

type dappDetails = {
  dappDomain?: string;
  dappLogo?: string;
};

export type StringDataResponse = {
  success: boolean;
  data?: string;
  message?: string;
  error?: any;
};
send
send(
  calldata: SendParams,
  dappDetails?: dappDetails,
  authUrl: string = triaAuthUrl,
  environment: ENV = 'mainnet'
): Promise<TxnResponse>

type SendParams = {
  amount: number;
  recepientAddress: string;
  chainName: string;
  tokenAddress?: string;
};

export type dappDetails = {
  dappDomain?: string;
  dappLogo?: string;
};

type TxnResponse {
  success: boolean;
  data?: TxnDataResponse;
  message?: string;
  error?: any;
}

type TxnDataResponse = {
  txnId: string;
  viewInExplorer: string;
  wait?: Function;
};
readContract
readContract(
  params: ReadContractParams
): Promise<ReadContractResponse>

type ReadContractParams = {
  chainName: string;
  contractDetails: ContractDetails;
};

type ContractDetails = {
  contractAddress: string;
  abi: Object[];
  functionName: string;
  args: any[];
  value?: number;
};

type ReadContractResponse = {
  success: boolean;
  data?: any;
  message?: string;
  error?: any;
};
writeContract
writeContract(
  calldata: WriteContractParams,
  dappDetails?: dappDetails,
  authUrl: string = triaAuthUrl,
  environment: ENV = 'mainnet'
): Promise<TxnResponse>

type WriteContractParams = {
  chainName: string;
  payToken?: {
    tokenAddress: string;
    amount: number;
  };
  contractDetails: ContractDetails;
};

type ContractDetails = {
  contractAddress: string;
  abi: Object[];
  functionName: string;
  args: any[];
  value?: number;
  enableTriaName?: boolean; // true if wanna pass triaName in args[]
};

export type dappDetails = {
  dappDomain?: string;
  dappLogo?: string;
};

type TxnResponse {
  success: boolean;
  data?: TxnDataResponse;
  message?: string;
  error?: any;
}

type TxnDataResponse = {
  txnId: string;
  viewInExplorer: string;
  wait?: Function;
};
sendNft
sendNft(
  calldata: SendNftParams,
  dappDetails?: dappDetails,
  authUrl: string = triaAuthUrl,
  environment: ENV = 'mainnet'
): Promise<TxnResponse>;

type SendNftParams = {
  chainName: string;
  recipientTriaName: string;
  nftDetails: {
    type: string;
    tokenAddress: string;
    tokenId: string;
    amount: number;
  };
};

type dappDetails = {
  dappDomain?: string;
  dappLogo?: string;
};

type TxnResponse {
  success: boolean;
  data?: TxnDataResponse;
  message?: string;
  error?: any;
}

type TxnDataResponse = {
  txnId: string;
  viewInExplorer: string;
  wait?: Function;
};
encrypt
encrypt(
  calldata: EncryptParams,
  dappDetails?: dappDetails,
  authUrl: string = triaAuthUrl,
  environment: ENV = 'mainnet'
): Promise<StringDataResponse>

type EncryptParams = {
  chainName: string;
  data: string;
  version?: string | 'x25519-xsalsa20-poly1305';
};

type dappDetails = {
  dappDomain?: string;
  dappLogo?: string;
};

type StringDataResponse = {
  success: boolean;
  data?: string;
  message?: string;
  error?: any;
};
decrypt
decrypt(
  calldata: DecryptParams,
  dappDetails?: dappDetails,
  authUrl: string = triaAuthUrl,
  environment: ENV = 'mainnet'
): Promise<StringDataResponse>

type DecryptParams = {
  chainName: string;
  encryptedData: string;
};

type dappDetails = {
  dappDomain?: string;
  dappLogo?: string;
};

type StringDataResponse = {
  success: boolean;
  data?: string;
  message?: string;
  error?: any;
};
approve
approve (
  config: Config,
  calldata: ApproveParams,
  authUrl: string = triaAuthUrl,
  environment: ENV = "mainnet",
  aa?: AaDetails,
  dappDetails?: dappDetails
): Promise<TxnResponse>;
type ApproveParams = {
  payload: Approve;
  chain?: ChainData;
};
type Approve = {
    tokenAddress: string;
    amount: number;
    spender: string;
    infinite?: boolean;
}
checkTokenAllowance
checkTokenAllowance ({
  config,
  calldata,
  environment = "mainnet",
}: {
  config: Config;
  calldata: CheckTokenAllowanceParams;
  environment: ENV;
}): Promise<CheckTokenAllowanceResponse>;
type CheckTokenAllowanceParams = {
  triaName: string;
  payload: Approve;
  chain: ChainData;
};
type Approve = {
    tokenAddress: string;
    amount: number;
    spender: string;
    infinite?: boolean;
}
type CheckTokenAllowanceResponse = {
    success: boolean;
    allowance?: boolean;
    message?: string;
}
broadcastTransaction
broadcastTransaction (
  config: Config,
  calldata: BroadcastTxnParams,
  authUrl: string = triaAuthUrl,
  environment: ENV = "mainnet",
  aa?: AaDetails,
  dappDetails?: dappDetails
): Promise<TxnResponse>;
type BroadcastTxnParams = {
    txnObject: Object;
    chain?: ChainData;
};
getBridgeQuote
getBridgeQuote (
  calldata: BridgeParams,
): Promise<GetBridgeQuoteResponse>;
type BridgeParams = {
    src: {
        chain: ChainData;
        token: {
            address: string;
            amountInUnits: string | "auto";
            amount?: number;
            decimals?: number;
        };
        senderAddress: string;
    };
    dest: {
        chainId: number;
        token: {
            address: string;
            amountInUnits: string | "auto";
            amount?: number;
            decimals?: number;
        };
        recipientAddress: string;
        externalCall?: {
            version: "evm_1" | "solana_1";
            fields: {
                to?: string;
                data?: string;
                gas?: number;
                calldata?: string;
            };
        };
    };
};
type GetBridgeQuoteResponse = {
    success: boolean;
    data?: {
        estimation: {
            srcChainTokenIn: {
                address: string;
                name: string;
                symbol: string;
                decimals: number;
                amount: string;
                approximateOperatingExpense: string;
                mutatedWithOperatingExpense: true;
            };
            srcChainTokenOut: {
                address: string;
                name: string;
                symbol: string;
                decimals: number;
                amount: string;
                maxRefundAmount: string;
            };
            dstChainTokenOut: {
                address: string;
                name: string;
                symbol: string;
                decimals: number;
                amount: string;
                recommendedAmount: string;
                withoutAdditionalTakerRewardsAmount: string;
                maxTheoreticalAmount: string;
            };
            recommendedSlippage: number;
            costsDetails: [string];
        };
        prependedOperatingExpenseCost: string;
        tx: {
            allowanceTarget: string;
            allowanceValue: string;
        };
        order: {
            approximateFulfillmentDelay: number;
        };
        fixFee: string;
        userPoints: number;
        integratorPoints: number;
        actualUserPoints: number;
        actualIntegratorPoints: number;
    };
    message?: string;
};
createBridgeTxn
createBridgeTxn (
  calldata: BridgeParams,
): Promise<CreateBridgeTxnResponse>;
type CreateBridgeTxnResponse = {
    success: boolean;
    data?: {
        estimation: {
            srcChainTokenIn: {
                address: string;
                name: string;
                symbol: string;
                decimals: number;
                amount: string;
                approximateOperatingExpense: string;
                mutatedWithOperatingExpense: true;
            };
            srcChainTokenOut: {
                address: string;
                name: string;
                symbol: string;
                decimals: number;
                amount: string;
                maxRefundAmount: string;
            };
            dstChainTokenOut: {
                address: string;
                name: string;
                symbol: string;
                decimals: number;
                amount: string;
                recommendedAmount: string;
                withoutAdditionalTakerRewardsAmount: string;
                maxTheoreticalAmount: string;
            };
            recommendedSlippage: number;
            costsDetails: [string];
        };
        tx: {
            to: string;
            data: string;
            value: string;
            gasLimit: number;
        };
        orderId: string;
        prependedOperatingExpenseCost: string;
        order: {
            approximateFulfillmentDelay: number;
        };
        fixFee: string;
        userPoints: number;
        integratorPoints: number;
        actualUserPoints: number;
        actualIntegratorPoints: number;
    };
    message?: string;
};
cancelBridgeTxn
cancelBridgeTxn (
  calldata: CancelBridgeTxnParams,
): Promise<CancelBridgeTxnResponse>;
type CancelBridgeTxnParams = {
  orderId: string;
};
type CancelBridgeTxnResponse = {
  success: boolean;
  data?: {
    to: string;
    data: string;
    value: string;
    chainId: number;
    from: string;
    cancelBeneficiary: string;
  };
  message?: string;
};
createSolanaCalldata
createSolanaCalldata (
  instructionsData: PlainInstructionData[]
): Promise<{ data: { calldata: string }, success: boolean }>;

Refer How to create Debridge Solana Calldata to understand better.

/**
 * Substitutes amount at offset with `walletBalance(accounts[account_index]) - subtraction`
 */
export type AmountSubstitution = {
  /**
   * big or little endian
   */
  is_big_endian: boolean;
  /**
   * At what offset substitution should be done
   */
  offset: number;
  /**
   * index of account in TransactionInstruction.keys to get balance for
   */
  account_index: number;
  /**
   * Amount to deduct from wallet balance
   */
  subtraction: number;
};

/**
 * Since we don't know submissionAuth at the moment of calldata preparation we can prepare substitution to replace
 * account at `index` with actual ATA(submissionAuth, tokenMint) during execution
 */
export type WalletSubstitution = {
  /**
   * Token mint to calculate ATA for
   */
  token_mint: string;
  /**
   * Account at this index will be replaced with ATA(submissionAuth, tokenMint) during execution
   */
  index: number;
};

/** Please note that all PublicKey are formatted in string (toBase58), expense and reward are also passed in string, and internally we format it back to BigInt, so please pass the values accordingly.*/
export type PlainInstructionData = {
  instruction: {
    keys: { pubkey: string /** base 58*/; isSigner: boolean; isWritable: boolean }[];
    programId: string; // base58
    data: string;
  };
  substitutions?: {
    amountSubstitutions?: AmountSubstitution[];
    walletSubstitutions?: WalletSubstitution[];
  };
  expense?: string; // should be in BigInt value converted to string
  reward?: string; // should be in BigInt value converted to string
  isInMandatoryBlock?: boolean;
};
signAndSendTransaction [SOLANA]
signAndSendTransaction = async ({
  chainName,
  transaction,
  authUrl = triaAuthUrl,
}: // dappDetails,
{
  chainName: "SOLANA" | string;
  transaction: any; // Solana web3 Transaction
  authUrl: string;
  dappDetails?: dappDetails;
}): Promise<StringDataRespo

Types

ChainData
type ChainData = {
    chainName?: string;
    customChain?: CustomChainData;
};
type CustomChainData = {
    type?: "EVM" | "SOL";
    chainId: number;
    rpcUrl: string;
    currencySymbol?: string;
    currencyName?: string;
    chainName?: string;
    chainLogo?: string;
    explorerUrl?: string;
};
BridgeParams
type BridgeParams = {
    src: {
        chain: ChainData;
        token: {
            address: string;
            amountInUnits: string | "auto";
            amount?: number;
            decimals?: number;
        };
        senderAddress: string;
    };
    dest: {
        chainId: number;
        token: {
            address: string;
            amountInUnits: string | "auto";
            amount?: number;
            decimals?: number;
        };
        recipientAddress: string;
        externalCall?: {
            version: "evm_1" | "solana_1";
            fields: {
                to?: string;
                data?: string;
                gas?: number;
                calldata?: string;
            };
        };
    };
};

Steps to integrate bridge:

  1. Use the getQuoteBridge function to get the quote for erc20 tokens and their allowance target and value.

  2. Use this this allowance target and value, to checkTokenAllowance, and approve for erc20 token

  3. Use the createBridgeTxn to get the txn object for the bridge txn

  4. Use the broadcastTransaction function to sign and send this txn object on-chain.

  5. To cancel a txn, use the cancelBridgeTxn with the orderId returned in the createBridgeTxn response

Last updated