Provider API

connect(connect wallet)

const res = await NaboxWallet.aptos.connect();
// 返回值
{
    address: '0xd2cefbc892ec340.....eafd72c9d035629f6ea49df', // Account Address
    publicKey: '0x63a97883e17f83......e1604beeb8ff984aa3fd1a' // Public Key(ed25519)
}

account (get connected account information)

const res = await NaboxWallet.aptos.connect();
// 返回值
{
    address: '0xd2cefbc892ec340.....eafd72c9d035629f6ea49df', // Account Address
    publicKey: '0x63a97883e17f83......e1604beeb8ff984aa3fd1a' // Public Key(ed25519)
}

network (get the currently connected network)

const network = await NaboxWallet.aptos.network();

// "Mainnet"

signAndSubmitTransaction (sign and broadcast transaction)

const transaction = {
  arguments: ['0xd2cefbc892ec340.....eafd72c9d035629f6ea49df', '666'],
  function: '0x1::coin::transfer',
  type: 'entry_function_payload',
  type_arguments: ['0x1::aptos_coin::AptosCoin'],
};

const pendingTransaction = NaboxWallet.aptos.signAndSubmitTransaction(transaction);

type PendingTransactionResponse = {
    type: TransactionResponseType.Pending;
    hash: string;
    sender: string;
    sequence_number: string;
    max_gas_amount: string;
    gas_unit_price: string;
    expiration_timestamp_secs: string;
    payload: TransactionPayloadResponse;
    signature?: TransactionSignature;
};
const transaction = {
  arguments: ['0xd2cefbc892ec340.....eafd72c9d035629f6ea49df', '666'],
  function: '0x1::coin::transfer',
  type: 'entry_function_payload',
  type_arguments: ['0x1::aptos_coin::AptosCoin'],
};

const signedTransaction = NaboxWallet.aptos.signTransaction(transaction);

// Returns the signed transaction object

signMessage(sign message)

interface SignMessagePayload {
  address?: boolean; // Do you need to add the current account address to the return value?
  application?: boolean; // Is it necessary to add the DApp domain name in the return value?
  chainId?: boolean; // chain id
  message: string; // Messages requiring signature
  nonce: string; // NONCE value
}

const messagePayload = {
  message: 'helllo aptos'; // Messages requiring signature
  nonce: 'aptos1'; // NONCE value
};

const res = NaboxWallet.aptos.signMessage(messagePayload);

interface SignMessageResponse {
  address: string; // The current signing account address
  application: string;// domain name
  chainId: number; // Current aptos chain id
  fullMessage: string; // Complete signature information
  message: string; // Signed Message
  nonce: string; // Signature nonce value
  prefix: string; // aptos prefix
  signature: string; // Signed message
}

// SignMessageResponse

Event

//  Monitor account changes
NaboxWallet.aptos.onAccountChange((changeAccount) => {
  console.log(changeAccount);
});

// Listening for disconnections
NaboxWallet.aptos.onDisconnect(() => {
  console.log('disconnected');
});

Last updated