/******************************************************************************* * (c) 2023 unipackage * * Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0 * (the "Apache License"). You may not use this file except in compliance with one of these * licenses. You may obtain a copy of the MIT License at * * https://opensource.org/licenses/MIT * * Or the Apache License, Version 2.0 at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the MIT License or the Apache License for the specific language governing permissions and * limitations under the respective licenses. ********************************************************************************/ import { Web3, TransactionReceipt, AbiFunctionFragment, Numbers } from "web3"; import { EtherUnits } from "web3-utils"; import { SignTransactionResult as Web3Signature } from "web3-eth-accounts"; import { Result } from "@unipackage/utils"; import type { Contract } from "web3-eth-contract"; import { EvmEventArgs, EvmInput, EvmOutput, EvmTransactionOptions, EvmType, IEVMEngine } from "../../interface"; import { IWallet } from "../../interface/wallet"; /** * Define ethereum as an optional property. */ declare global { interface Window { ethereum?: any; } } /** * Class representing a Web3Evm instance. */ export declare class Web3EvmEngine implements IEVMEngine { private web3Object; private contractObject; private contractAddress; private contractABI; private providerUrl; wallet: IWallet | undefined; /** * Constructor for Web3Evm class. * * @TODO test window.ethereum * @param contractABI - The contract's ABI. * @param contractAddress - The contract's address. * @param providerUrl - The provider URL. */ constructor(contractABI: AbiFunctionFragment[], contractAddress: string, providerUrl?: string, wallet?: IWallet); /** * Generates a value in Wei based on the provided number and unit. * * @param number - The number to convert to Wei. * @param unit - The unit to convert the number to (e.g., Ether, Gwei). * @returns The generated value in Wei as a string or bigint. */ generateWei(number: Numbers, unit: EtherUnits): string; /** * Generates a transaction based on input and options. * * @param input - The EVM input. * @param options - The transaction options. * @returns A promise resolving to EvmOutput object with the transaction. */ private generateTransaction; /** * Initializes the contract. * * @param contractABI - The contract's ABI. * @param contractAddress - The contract's address. * @returns EvmOutput object indicating success or failure. */ private initContract; /** * Calls a contract function. * * @param input - The EVM input. * @returns A promise resolving to EvmOutput object with the result of the contract call. */ call(input: EvmInput): Promise>; /** * Decodes transaction input. * * @param txInput - The transaction input. * @returns A promise resolving to EvmOutput object with the decoded transaction input. */ decodeTxInputToEvmInput(txInput: string): EvmOutput; /** * Encodes EVM input to transaction input. * * @param input - The EVM input. * @returns Result object with the encoded transaction input. */ encodeEvmInputToTxinput(input: EvmInput): Result; encodeFunctionSignatureByAbi(abi: AbiFunctionFragment): Result; /** * Encodes function signature. * * @param name - The name of the function. * @returns Result object with the encoded function signature. */ encodeFunctionSignatureByFuntionName(name: string): Result; /** * Retrieve the wallet instance. * * This method returns the instance of the wallet that implements the IWallet interface. * Clients can use this method to access and manage the wallet's functionalities. * * @returns An instance of the wallet implementing the IWallet interface. */ getWallet(): IWallet; /** * Contract getter. * * @NOTE check contract not null when using in window.ethereum * @returns Contract instance or null. */ getContract(): Contract | null; /** * Get the EVM contract address. * * @returns The EVM contract address or null if not initialized. */ getContractAddress(): string; /** * Get the EVM contract abi. * * @returns The EVM contract abi or null if not initialized. */ getContractABI(): AbiFunctionFragment[]; /** * Extracts Ethereum Virtual Machine (EVM) event arguments from a transaction receipt. * * @param transactionReceipt - The transaction receipt containing event data. * @param name - The name of the event. * @returns An object representing the extracted EVM event arguments. */ getEvmEventArgs(transactionReceipt: TransactionReceipt, name: string): EvmOutput; /** * Get the EVM type. * * @returns The EVM type,Web3 or Ethers. */ getEvmType(): EvmType; /** * Get the EVM provider url. * * @returns The EVM provider url or null if not initialized. */ getProviderUrl(): string | undefined; /** * Get the Ether Provider * * @returns Ether Provider object or null if not initialized. */ getEtherProvider(): null; /** * Web3 getter. * * @returns Web3 instance or null. */ getWeb3(): Web3 | null; /** * Sends a transaction. * * @TODO test window.ethereum * @param input - The EVM input. * @param options - The transaction options. * @returns A promise resolving to EvmOutput object with the result of the transaction. */ send(input: EvmInput, options?: EvmTransactionOptions): Promise>; /** * Sends a signed transaction. * * @param signedTransaction - The signed transaction. * @returns A promise resolving to EvmOutput object with the result of the signed transaction. */ sendSigned(signedTransaction: Web3Signature): Promise>; /** * Signs a transaction. * * @param input - The EVM input. * @param options - The transaction options. * @returns A promise resolving to Result object with the signed transaction. */ sign(input: EvmInput, options?: EvmTransactionOptions): Promise>; } //# sourceMappingURL=index.d.ts.map