tonkey-gateway-typescript-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.0.5-beta • Public • Published

tonkey-gateway-typescript-sdk

Installation

npm i tonkey-gateway-typescript-sdk
npm i @apollo/client

Add provider to your code

import { ApolloClient, InMemoryCache, ApolloProvider } from "@apollo/client";

const client = new ApolloClient({
  uri: GRAPHQL_URI || "",
  cache: new InMemoryCache(),
  connectToDevTools: true,
});

<ApolloProvider client={client}>
    {children}
</ApolloProvider>

Example

Get Safe Info

const { safeInfo, loading, error } = useWalletByAddress(address, chainId);

//address:TON raw address
//chainId: Mainnet: -239, Testnet: -3

Get list of safe owned by a wallet address

const { safeList, loading, error, refetch } = useWalletsByOwnerAddress(address);

//address:TON raw address

To get the list again after first query

refetch({ ownerAddress: yourAddress });

//ownerAddress:TON raw address

Get list of transaction history

const { data, error, loading } = useTxHistory(address, chainId, POLLING_INTERVAL);

/address:TON raw address
//chainId: Mainnet: -239, Testnet: -3
//POLLING_INTERVAL: number, unit: ms

Get list of transaction queue

const { data, error, loading } = useTxQueue(address, chainId, POLLING_INTERVAL);

//address:TON raw address
//chainId: Mainnet: -239, Testnet: -3
//POLLING_INTERVAL: number, unit: ms

Get balance of a specific safe

const { data, error, loading, refetch } = useGetBalanceBySafeAddress(address, chainId, POLLING_INTERVAL);

//address:TON raw address
//chainId: Mainnet: -239, Testnet: -3
//POLLING_INTERVAL: number, unit: ms

To get the balance again after first query

refetch({ chainId: chainId, safeAddress: rawAddress });

Propose new Transaction

Contains 2 steps

  1. Generate payload to server
const payload = await getTransferpayload(transferParams);

transferParams:

{
  "recipient": "kQCmxsVr-UHBmi0lUTAFcI2q7C7zItI8czKuzjBX7yjvhdoM", //recipient's ton address
  "amount": "10000000", //amount in nanoTon
  "orderCellBoc": "bocCompiledFrom Tonkey-core-sdk", //to see how to build it checkout tonkey-coe-sdk
  "queryId": "6488358a00000000", //you will get this info from tonkey-coe-sdk (createOrder)
  "expiredTime": "1686648202000", //you will get this info from tonkey-coe-sdk (createOrder)
  "wallet": {
    "address": "0:a6c6c56bf941c19a2d25513005708daaec2ef322d23c7332aece3057ef28ef85", //ton raw address
    "chain": "-3" //Mainnet: -239, Testnet: -3
  },
  "safe": {
    "address": "0:d4e1d52bdecd315d8685cfccc985e2cf7da6fe39ab6617b420df914197f14b30",
    "chainId": "-3",
    "owners": [
      {
        "address": "0:a6c6c56bf941c19a2d25513005708daaec2ef322d23c7332aece3057ef28ef85",
        "publicKey": "8d2f6c1743b61633094c91356bb4f0697286a89a624856f1a672ab97e119105b"
      },
      {
        "address": "0:1f517d873e59c3b4b6f5dcafe87202231086920732d4386faa3cdefaf0912a62",
        "publicKey": "ba9f6848becef9ccaf265d79a78af22127b0fc089c6a489ea57f0a0bed76e98b"
      }
    ],
    "safeId": "61709",
    "threshold": 1,
    "walletId": "61709"
  }, //you will get all the columns from Get Safe Info method above
  "tokenInfo": {
    "jettonMinterAddress": "000000",
    "tokenName": "Toncoin",
    "tokenSymbol": "TON",
    "logoUri": "https://ton.org/download/ton_symbol.svg",
    "decimals": 9
  }, //you can get tokenInfo from Get balance of a specific safe method
  "signatures": [
    "9177a7c7fe2e91e067490737883f8a2e804caef0894f9230a749ac10def2420bcd19c5ae8af7b0afc65a17f2da51e8f0d640191a1265248ebbab9b20852d3003",
    ""
  ] //please refer to tonkey-core-sdk using Sign with OpenMask
}

After getting the payload

  1. Send payload to server
  const { createTransfer, data, loading, error } = useCreateNativeTransfer();
  await createTransfer({ variables: { content: payload } });

Readme

Keywords

none

Package Sidebar

Install

npm i tonkey-gateway-typescript-sdk

Weekly Downloads

1

Version

2.0.5-beta

License

MIT

Unpacked Size

33.6 kB

Total Files

22

Last publish

Collaborators

  • tonkey-gateway