Tomo Docs
Tomo Docs
  • Overview
    • Introducing Tomo
    • Tomo's Key Management
  • Tomo SDK
    • TomoEVMKit
      • Quick Start
      • Use with Ethers.js
      • Migration from RainbowKit
      • Migration from Blocknative
      • Supported Chains
    • Tomo Web SDK
      • Quick Start
      • Solana Provider
      • EVM Provider
      • Bitcoin Provider
      • Tron Provider
      • Movement Provider
      • Sui Provider
    • Tomo Telegram SDK
      • Quick Start
      • Wallet Provider
        • EVM Provider
        • Solana Provider
        • Sui Provider (Beta)
        • TON Provider
      • Partners
    • Tomo Enterprise SDK
      • For Babylon
        • Install the SDK
        • Tomo Wallet Provider
        • Bitcoin Provider
        • Cosmos Provider
        • Multiple Connection Mode
        • Integrate Extension Wallet
          • Submit Wallet PR
          • Extend the SDK
          • Q & A
        • Integrate Mobile Wallet
  • TOMO WALLET
    • Tomo Wallets
    • Mobile Wallet
      • Tomo Keys
        • Bonding Curve Explained
        • How to: Tomo Keys
      • TomoID
        • How to: TomoID
        • How to: Connect Instagram
      • Tomo Socials
      • Tomo Android App
      • Tomo iOS App
    • Extension Wallet
      • Developer Manual
        • EVM Integration
        • Bitcoin Integration
      • Example of User Flows
        • Claiming Signet BTC
        • Staking at Testnet
      • Install Link
    • Telegram Wallet
      • Quick Start
      • Chains/Networks
      • User Manual
        • Account Security
        • Gift feature
        • FAQ
        • Transaction
        • Swap
  • ABOUT US
    • Brand Assets
    • Privacy Policy
Powered by GitBook
On this page
  • Get Movement Address
  • Provider Functions
  • Signing a Message
  • Sign Transaction
  • Send Transaction
  • Example
  • React
  • Pure JS
  1. Tomo SDK
  2. Tomo Web SDK

Movement Provider

After setting up your wallet, you can have access to the Movement provider:

// react
const { providers } = useTomo()
const { movementProvider } = providers;

// pure js
const tronProvider = window.tomo_movement

Get Movement Address

The Movement address is from the wallet state or provider. In React framework:

import { useTomo} from '@tomo-inc/tomo-web-sdk';
const { walletState, providers } = useTomo()

// get from wallet state
const movementAddress = walletState.movementAddress

// or get from provider
const movementAddress = await providers.movementProvider.getAddress()

Or Pure JS:

/** pure js */
import { getWalletState } from '@tomo-inc/tomo-web-sdk';
/** pure js */
// get from wallet state
const movementAddress = getWalletState().movementAddress

// or get from provider
const movementAddress = await window.tomo_movement.getAddress()

Provider Functions

Signing a Message

It uses the Movement provider to sign a plaintext message with a nonce. The output is a response message output defined as below:

// interface
signMessage(
  input: AptosSignMessageInput
): Promise<UserResponse<AptosSignMessageOutput>>;

type AptosSignMessageInput = {
  address?: boolean;
  application?: boolean;
  chainId?: boolean;
  message: string;
  nonce: string;
};

declare enum UserResponseStatus {
  APPROVED = "Approved",
  REJECTED = "Rejected",
}

interface UserApproval<TResponseArgs> {
  status: UserResponseStatus.APPROVED;
  args: TResponseArgs;
}

interface UserRejection {
  status: UserResponseStatus.REJECTED;
}

type UserResponse<TResponseArgs> =
  | UserApproval<TResponseArgs>
  | UserRejection;

type AptosSignMessageOutput = {
  address?: string;
  application?: string;
  chainId?: number;
  fullMessage: string;
  message: string;
  nonce: string;
  prefix: "APTOS";
  signature: Signature;
};

// example
const signedMessage = await movementProvider.signMessage({
  message: "hello movement",
  nonce: "123",
});

Sign Transaction

To sign a transaction, you need to create a AnyRawTransaction from Aptos SDK and send it to the movement Provider for signing.

// interface
import {
  AnyRawTransaction,
  AptosConfig,
  Aptos,
  AccountAddress,
} from "@aptos-labs/ts-sdk";

signTransaction(
  transaction: AnyRawTransaction,
  asFeePayer?: boolean
): Promise<SignedTransaction>;

// example
const config = new AptosConfig({
  fullnode: yourRpcUrl,
});

const client = new Aptos(config);

const transaction = await client.transaction.build.simple({
  sender: AccountAddress.fromString(fromAddress),
  data: {
    functionArguments: [
      AccountAddress.fromString(toAddress),
      +value,
    ],
    function: "0x1::aptos_account::transfer",
  },
});

const signedRes = await movementProvider.signTransaction(transaction);

Send Transaction

Our movement provider also supports signing and submitting a transaction through one call, which require a InputGenerateTransactionPayloadData as inputs.

// interface
import { InputGenerateTransactionPayloadData } from "@aptos-labs/ts-sdk";

signAndSubmitTransaction(
  transaction: AptosSignAndSubmitTransactionInput
): Promise<SignedTransaction>;

interface AptosSignAndSubmitTransactionInput {
  gasUnitPrice?: number;
  maxGasAmount?: number;
  payload: InputGenerateTransactionPayloadData;
}

// example
const transaction: { payload: InputEntryFunctionData } = {
  payload: {
    functionArguments: ["0x34324...", 123],
    function: "0x1::aptos_account::transfer",
  },
};

const sendRes = await movementProvider.signAndSubmitTransaction(transaction);

Example

React

import {
  AnyRawTransaction,
  AptosConfig,
  Aptos,
  AccountAddress,
  InputEntryFunctionData,
} from "@aptos-labs/ts-sdk";
import { TomoContextProvider, useTomo } from "@tomo-inc/tomo-web-sdk";

const CLIENT_ID = "Your client id";

enum Theme {
  Light = "light",
  Dark = "dark",
}

export default function MovementDemo() {
  return (
    <TomoContextProvider
      theme={Theme.Light}
      chainTypes={["movement"]}
      clientId={CLIENT_ID}
    >
      <App />
    </TomoContextProvider>
  );
}

export function App() {
  const { providers, walletState, openConnectModal } = useTomo();
  const { movementProvider } = providers;

  return (
    <div style={{ display: "flex", gap: "10px" }}>
      <button onClick={openConnectModal}>openConnectModal</button>

      <button
        onClick={async () => {
          if (!movementProvider) throw new Error("movementProvider not found");

          try {
            const config = new AptosConfig({ fullnode: yourRpcUrl });
            const client = new Aptos(config);

            const transaction = await client.transaction.build.simple({
              sender: AccountAddress.fromString(fromAddress),
              data: {
                functionArguments: [AccountAddress.fromString(toAddress), value],
                function: "0x1::aptos_account::transfer",
              },
            });

            const signRes = await movementProvider.signTransaction(transaction);
            console.log("signRes>>>", signRes);

            if (signRes?.status === UserResponseStatus.REJECTED) {
              throw new Error("User rejected the request or failed to sign Move transaction");
            }

            console.log("The transaction was signed successfully:", signRes.args);
          } catch (error) {
            console.error("Error signing transaction:", error);
          }
        }}
      >
        sign transaction
      </button>

      <button
        onClick={async () => {
          if (!movementProvider) throw new Error("movementProvider not found");

          try {
            const transaction: { payload: InputEntryFunctionData } = {
              payload: {
                functionArguments: [address, 123],
                function: "0x1::aptos_account::transfer",
              },
            };

            const sendRes = await movementProvider.signAndSubmitTransaction(transaction);
            console.log("sendRes>>>", sendRes);

            if (sendRes?.status === UserResponseStatus.REJECTED) {
              throw new Error("User rejected the request or failed to send Move transaction");
            }

            console.log("The transaction was sent successfully:", sendRes.args.hash);
          } catch (error) {
            console.error("Error signing and submitting transaction:", error);
          }
        }}
      >
        sign and submit transaction
      </button>
    </div>
  );
}

Pure JS

import { initTomoModal } from "@tomo-inc/tomo-web-sdk";
import {
  AnyRawTransaction,
  AptosConfig,
  Aptos,
  AccountAddress,
  InputEntryFunctionData,
} from "@aptos-labs/ts-sdk";

const CLIENT_ID = "Your client id";

enum Theme {
  Light = "light",
  Dark = "dark",
}

initTomoModal({
  theme: Theme.Light,
  clientId: CLIENT_ID,
  chainTypes: ["movement"],
});

export default function MovementDemo() {
  return (
    <div style={{ display: "flex", gap: "10px" }}>
      <button onClick={() => window.openTomoConnectModal?.()}>
        openConnectModal
      </button>

      <button
        onClick={async () => {
          if (!window.movementProvider)
            throw new Error("movementProvider not found");

          try {
            const config = new AptosConfig({ fullnode: yourRpcUrl });
            const client = new Aptos(config);

            const transaction = await client.transaction.build.simple({
              sender: AccountAddress.fromString(fromAddress),
              data: {
                functionArguments: [
                  AccountAddress.fromString(toAddress),
                  value,
                ],
                function: "0x1::aptos_account::transfer",
              },
            });

            const signRes = await window.movementProvider.signTransaction(
              transaction
            );
            console.log("signRes>>>", signRes);

            if (signRes?.status === UserResponseStatus.REJECTED) {
              throw new Error(
                "User rejected the request or failed to sign Move transaction"
              );
            }

            console.log("The transaction was signed successfully:", signRes.args);
          } catch (error) {
            console.error("Error signing transaction:", error);
          }
        }}
      >
        sign transaction
      </button>

      <button
        onClick={async () => {
          if (!window.movementProvider)
            throw new Error("movementProvider not found");

          try {
            const transaction: { payload: InputEntryFunctionData } = {
              payload: {
                functionArguments: [address, 123],
                function: "0x1::aptos_account::transfer",
              },
            };

            const sendRes =
              await window.movementProvider.signAndSubmitTransaction(transaction);
            console.log("sendRes>>>", sendRes);

            if (sendRes?.status === UserResponseStatus.REJECTED) {
              throw new Error(
                "User rejected the request or failed to send Move transaction"
              );
            }

            console.log(
              "The transaction was sent successfully:",
              sendRes.args.hash
            );
          } catch (error) {
            console.error("Error signing and submitting transaction:", error);
          }
        }}
      >
        sign and submit transaction
      </button>
    </div>
  );
}
PreviousTron ProviderNextSui Provider

Last updated 1 month ago

We provide an as follows:

example