signTransaction

Open a JoyID app popup window to sign a AXON transaction.

Types

function signTransaction (
  // The tx that was requested to be signed
  tx: TransactionRequest,
  config?: SignConfig
): Promise<string>

interface TransactionRequest {
  to?: string
  from: string
  nonce?: string
  gasLimit?: string
  gasPrice?: string
  data?: string
  value?: string
  chainId?: number
  customData?: Record<string, any>
  ccipReadEnabled?: boolean
}

interface SignConfig extends PopupConfig {
  /**
   * The name of your app
   */
  name?: string
  /**
   * The logo of your app
   */
  logo?: string
  /**
   * The RPC URL of the AXON node that your app is using, defaults to https://axon-rpc.internal.joyid.dev
   */
  rpcURL?: string
  /**
   * The network that your app is using, defaults to JoyID AXON devnet
   */
  network?: Network
  /**
   * The URL of JoyID app url that your app is integrated with, defaults to https://app.joyid.dev
   */
  joyidAppURL?: string
  /**
   * The URL of JoyID server url that your app is integrated with
   */
  joyidServerURL?: string
}

interface PopupConfig {
  /**
   * Default is 300s
   */
  timeoutInSeconds?: number
  /**
   * popup instance
   */
  popup?: Window
}

interface Network {
  name: string
  chainId: number
}

Example

import { signTransaction } from '@joyid/evm'
import { parseEther } from 'ethers'

async function joyidSignTranaction() {
  try {
    // send 0.1 ether to `0xA6eBeCE9938C3e1757bE3024D2296666d6F8Fc49`
    const signedTx = await signTransaction({
        from: '0x71372492b5bc6ae526fed2cda57919c2b0156afe',
        to: '0xA6eBeCE9938C3e1757bE3024D2296666d6F8Fc49',
        value: parseEther('0.1').toString(),
    })
    // send signed tx to blockchain
    const txHash = await provider.send('eth_sendRawTransaction', [signedTx])
    console.log(txHash)
  } catch (e) {
    console.error(e)
  }
}
Table of Contents