debeem-wallet

Please configure chain/network before using this class.

//	switch chain/network to Eth Sepolia
setCurrentChain( 11155111 );

// query currently supported chain/network
const supportedChains : Array<number> = new InfuraRpcService( 1 ).supportedChains();

// should return a supported chain list, for example:
[ 1, 11155111 ]

Constructors

Methods

  • query information about a block by blockHash

    Parameters

    • blockHash: string

      {string} A string representing the hash (32 bytes) of a block.

    • Optional transactionDetails: boolean

      {boolean} If set to true, returns the full transaction objects, if false returns only the hashes of the transactions.

    Returns Promise<BlockItem>

  • query information about a block by hexBlockNumber

    Parameters

    • hexBlockNumber: string

      {string} A hexadecimal block number, or one of the string tags latest, earliest, pending, safe, or finalized.

    • Optional transactionDetails: boolean

      {boolean} If set to true, returns the full transaction objects, if false returns only the hashes of the transactions.

    Returns Promise<BlockItem>

Send Transaction

  • Broadcast a transaction

    Parameters

    • signedTx: string

      {string} the string of the signed transaction object

    Returns Promise<TransactionResponse>

    Example

    //
    // This is a complete example of how to send a transaction using .signTransaction and .broadcastTransaction
    //

    // switch chain/network to Eth.Sepolia
    setCurrentChain( 11155111 );

    // try to create a wallet from a private key
    const publicWalletPrivateKey = '0xc7f832621897e67d973f0f1c497198ed1b89a138f2fe3cc6ce6a59cd3fb7cd4c';
    const walletObj = new WalletFactory().createWalletFromPrivateKey( publicWalletPrivateKey );

    //
    // send translation from [oneKey wallet 1] to [oneKey wallet 2]
    //
    const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
    const sendValue1 : string = '0.001124'; // in ETH

    let singedTx : string = await new WalletTransaction().signTransaction( walletObj, payeeAddress, sendValue1, -1, 100 );
    let broadcastResponse : TransactionResponse | undefined = undefined;
    try
    {
    broadcastResponse = await new WalletTransaction().broadcastTransaction( singedTx );
    }
    catch ( err : any )
    {
    const minimumNeededGas : TransactionMinimumNeededGas | null = new WalletTransaction().extractMinimumNeededGasLimit( err );
    if ( minimumNeededGas )
    {
    //
    // The reason for the abnormal transaction is that the gas fee is too low,
    // and we have successfully extracted the lowest gas fee reminder from the error
    //
    // Now, let’s try to send this transaction again with more gas fee.
    //
    singedTx = await new WalletTransaction().signTransaction( walletObj, payeeAddress, sendValue1, -1, minimumNeededGas.minimum + 100 );
    broadcastResponse = await new WalletTransaction().broadcastTransaction( singedTx );
    }
    else
    {
    // just throw the error again
    throw err;
    }
    }
  • Send a derivative token

    Parameters

    • contractAddress: string

      {string} contract address

    • wallet: WalletEntityBaseItem

      {WalletEntityBaseItem} wallet object

    • toAddress: string

      {string} recipient's wallet address

    • value: string

      {string} value string in ETH. for example: 0.01

    • Optional decimals: number = 18

      {number} decimals

    • Optional nonce: number = -1

      {number} nonce value

    • Optional gasLimit: number = 0

      {number} gas limit value, in wei

    Returns Promise<TransactionResponse>

    Example

    //
    // This is a complete example of how to send a transaction
    //

    // switch chain/network to Eth.Sepolia
    setCurrentChain( 11155111 );

    // try to create a wallet from a private key
    const publicWalletPrivateKey = '0xc7f832621897e67d973f0f1c497198ed1b89a138f2fe3cc6ce6a59cd3fb7cd4c';
    const walletObj = new WalletFactory().createWalletFromPrivateKey( publicWalletPrivateKey );

    //
    // send translation from [oneKey wallet 1] to [oneKey wallet 2]
    //
    const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
    const usdtContractAddress = '0x271B34781c76fB06bfc54eD9cfE7c817d89f7759'; // USDT contract address on sepolia
    const sendValueUsdt : string = '1.1'; // in USDT
    let broadcastResponse : TransactionResponse | undefined = undefined;
    try
    {
    broadcastResponse = await new WalletTransaction().sendContractToken
    (
    usdtContractAddress,
    walletObj,
    payeeAddress,
    sendValueUsdt,
    6
    );
    }
    catch ( err : any )
    {
    const minimumNeededGas : TransactionMinimumNeededGas | null = new WalletTransaction().extractMinimumNeededGasLimit( err );
    if ( minimumNeededGas )
    {
    //
    // The reason for the abnormal transaction is that the gas fee is too low,
    // and we have successfully extracted the lowest gas fee reminder from the error
    //
    // Now, let’s try to send this transaction again with more gas fee.
    //
    broadcastResponse = await new WalletTransaction().sendContractToken
    (
    usdtContractAddress,
    walletObj,
    payeeAddress,
    sendValueUsdt,
    6,
    -1,
    minimumNeededGas.minimum + 100
    );
    }
    else
    {
    // just throw the error again
    throw err;
    }
    }
  • send a native token

    Parameters

    • wallet: WalletEntityBaseItem

      {WalletEntityBaseItem} wallet object

    • to: string

      {string} recipient's wallet address

    • value: string

      {string} value in ETH. for example: '0.2' ETH

    • Optional nonce: number = -1

      {number} nonce value

    • Optional gasLimit: number = 0

      {number} gas limit value, in wei.

    Returns Promise<TransactionResponse>

    Example

    //
    // This is a complete example of how to send a native token using .sendToken
    //

    // switch chain/network to Eth.Sepolia
    setCurrentChain( 11155111 );

    // try to create a wallet from a private key
    const publicWalletPrivateKey = '0xc7f832621897e67d973f0f1c497198ed1b89a138f2fe3cc6ce6a59cd3fb7cd4c';
    const walletObj = new WalletFactory().createWalletFromPrivateKey( publicWalletPrivateKey );

    //
    // send translation from [oneKey wallet 1] to [oneKey wallet 2]
    //
    const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
    const sendValue2 : string = '0.0020010'; // in ETH
    let broadcastResponse : TransactionResponse | undefined = undefined;
    try
    {
    const nonce = await new WalletTransaction().queryNonce( walletObj.address );
    const estimatedGas = await new WalletTransaction().estimateEthGasLimitByToAddress( payeeAddress );
    broadcastResponse = await new WalletTransaction().sendToken( walletObj, payeeAddress, sendValue2, nonce, estimatedGas );
    }
    catch ( err : any )
    {
    const minimumNeededGas : TransactionMinimumNeededGas | null = new WalletTransaction().extractMinimumNeededGasLimit( err );
    if ( minimumNeededGas )
    {
    //
    // The reason for the abnormal transaction is that the gas fee is too low,
    // and we have successfully extracted the lowest gas fee reminder from the error
    //
    // Now, let’s try to send this transaction again with more gas fee.
    //
    broadcastResponse = await new WalletTransaction().sendToken( walletObj, payeeAddress, sendValue2, -1, minimumNeededGas.minimum + 100 );
    }
    else
    {
    // just throw the error again
    throw err;
    }
    }
  • sign a transaction of sending native token, before it will be broadcast

    Parameters

    • wallet: WalletEntityBaseItem

      {WalletEntityBaseItem}

    • toAddress: string

      {string} recipient's wallet address

    • value: string

      {string} ETH quantity, unit ETH, for example: "0.001" ETH

    • Optional nonce: number = -1

      {number} The nonce is very important. We can query the current nonce through the Infura API.

    • Optional gasLimit: number = 0

      {number} in wei. The gasLimit for sending ETH is fixed at 21,000. Transactions calling other contracts need to estimate the gasLimit in advance.

    Returns Promise<string>

Transaction Helper

  • estimate gas limit by transaction request object

    //
    // estimate gas limit by transaction request object
    //
    const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
    const transactionRequest : TransactionRequest = {
    to : payeeAddress,
    };
    const gasLimit = await new WalletTransaction().estimateEthGasLimit( transactionRequest );
    //
    // should return:
    // gasLimit : 21000
    //

    Parameters

    • transactionRequest: TransactionRequest

      {TransactionRequest} transaction request object

    Returns Promise<number>

    gas limit in wei.

  • estimate gas limit by recipient's wallet address

    //
    // estimate gas limit by transaction request object
    //
    const payeeAddress : string = `0x8B4c0Dc5AA90c322C747c10FDD7cf1759D343573`;
    const gasLimit = await new WalletTransaction().estimateEthGasLimitByToAddress( payeeAddress );
    //
    // should return:
    // gasLimit : 21000
    //

    Parameters

    • toAddress: AddressLike

      {AddressLike} recipient's wallet address

    Returns Promise<number>

    gas limit in wei.

query Transaction