TypeScript Wrapper
Fewcha Wallet provider is added by default window.fewcha
and you can use direct methods, look like
window.fewcha.signMessage( ...
window.fewcha.aptos.getAccountTransactions(...
window.fewcha.sui.getObjectsOwnedByAddress(...
window.fewcha.token.createCollection(...
Use TypeScript to strictly control the param passed and ensure window.fewcha
works well on your website. We recommend using @fewcha/web3
instead of use direct window.fewcha
Install
yarn add aptos @fewcha/web3
import Web3 from "@fewcha/web3";
const web3 = new Web3();
web3.action.connect();
web3.action.aptos.signMessage(...
web3.action.aptos.getAccountTransactions(...
web3.action.sui.signAndExecuteTransaction(...
web3.action.sui.getObjectsOwnedByAddress(...
You can take a look at all functions and types at https://github.com/fewcha-wallet/aptos-web3/blob/main/packages/web3/src/types.ts
export interface IWeb3Provider {
connect(): Promise<Response<PublicAccount>>;
disconnect(): Promise<Response<boolean>>;
isConnected(): Promise<Response<boolean>>;
account(): Promise<Response<PublicAccount>>;
getNetwork(): Promise<Response<string>>;
getNetworkURL(): Promise<Response<string>>;
getNetworkType(): Promise<Response<string>>;
getBalance(): Promise<Response<string>>;
aptos: IWeb3AptosSDK,
sui: IWeb3SuiSDK,
token: IWeb3AptosToken | IWeb3SuiToken;
coin: IWeb3Coin;
}
export type IWeb3SuiSDK = {
getMoveFunctionArgTypes(objectId: string, moduleName: string, functionName: string): Promise<Response<SuiMoveFunctionArgTypes>>;
getNormalizedMoveModulesByPackage(objectId: string): Promise<Response<SuiMoveNormalizedModules>>;
getNormalizedMoveModule(objectId: string, moduleName: string): Promise<Response<SuiMoveNormalizedModule>>;
getNormalizedMoveFunction(objectId: string, moduleName: string, functionName: string): Promise<Response<SuiMoveNormalizedFunction>>;
getNormalizedMoveStruct(objectId: string, moduleName: string, structName: string): Promise<Response<SuiMoveNormalizedStruct>>;
getObjectsOwnedByAddress(address: string): Promise<Response<SuiObjectInfo[]>>;
getGasObjectsOwnedByAddress(address: string): Promise<Response<SuiObjectInfo[]>>;
getObjectsOwnedByObject(objectId: string): Promise<Response<SuiObjectInfo[]>>;
getObject(objectId: string): Promise<Response<GetObjectDataResponse>>;
getObjectRef(objectId: string): Promise<Response<SuiObjectRef | undefined>>;
getObjectBatch(objectIds: string[]): Promise<Response<GetObjectDataResponse[]>>;
getTransactionsForObject(objectID: string): Promise<Response<GetTxnDigestsResponse>>;
getTransactionsForAddress(addressID: string): Promise<Response<GetTxnDigestsResponse>>;
getTransactionWithEffects(digest: TransactionDigest): Promise<Response<SuiTransactionResponse>>;
getTransactionWithEffectsBatch(digests: TransactionDigest[]): Promise<Response<SuiTransactionResponse[]>>;
executeTransaction(txnBytes: string, signatureScheme: SignatureScheme, signature: string, pubkey: string): Promise<Response<SuiTransactionResponse>>;
executeTransactionWithRequestType(txnBytes: string, signatureScheme: SignatureScheme, signature: string, pubkey: string, requestType?: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
getTotalTransactionNumber(): Promise<Response<number>>;
getTransactionDigestsInRange(start: GatewayTxSeqNumber, end: GatewayTxSeqNumber): Promise<Response<GetTxnDigestsResponse>>;
getRecentTransactions(count: number): Promise<Response<GetTxnDigestsResponse>>;
syncAccountState(address: string): Promise<Response<any>>;
getEventsByTransaction(digest: TransactionDigest, count?: number): Promise<Response<SuiEvents>>;
getEventsByModule(package_: string, module: string, count?: number, startTime?: number, endTime?: number): Promise<Response<SuiEvents>>;
getEventsByMoveEventStructName(moveEventStructName: string, count?: number, startTime?: number, endTime?: number): Promise<Response<SuiEvents>>;
getEventsBySender(sender: SuiAddress, count?: number, startTime?: number, endTime?: number): Promise<Response<SuiEvents>>;
getEventsByRecipient(recipient: ObjectOwner, count?: number, startTime?: number, endTime?: number): Promise<Response<SuiEvents>>;
getEventsByObject(object: ObjectId, count?: number, startTime?: number, endTime?: number): Promise<Response<SuiEvents>>;
getEventsByTimeRange(count?: number, startTime?: number, endTime?: number): Promise<Response<SuiEvents>>;
subscribeEvent(filter: SuiEventFilter, onMessage: (event: SuiEventEnvelope) => void): Promise<Response<SubscriptionId>>;
unsubscribeEvent(id: SubscriptionId): Promise<Response<boolean>>;
dryRunTransaction(txnBytes: string, signatureScheme: SignatureScheme, signature: string, pubkey: string): Promise<Response<TransactionEffects>>;
// Signer
signAndDryRunTransaction(txBytes: Base64DataBuffer): Promise<Response<TransactionEffects>>;
transferObjectDryRun(transaction: TransferObjectTransaction): Promise<Response<TransactionEffects>>;
executeMoveCallDryRun(transaction: MoveCallTransaction): Promise<Response<TransactionEffects>>;
transferSuiDryRun(transaction: TransferSuiTransaction): Promise<Response<TransactionEffects>>;
publishDryRun(transaction: PublishTransaction): Promise<Response<TransactionEffects>>;
signData(data: Base64DataBuffer): Promise<Response<SignaturePubkeyPair>>;
signAndExecuteTransaction(txBytes: Base64DataBuffer): Promise<Response<SuiTransactionResponse>>;
signAndExecuteTransactionWithRequestType(txBytes: Base64DataBuffer, requestType: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
transferObject(transaction: TransferObjectTransaction): Promise<Response<SuiTransactionResponse>>;
transferSui(transaction: TransferSuiTransaction): Promise<Response<SuiTransactionResponse>>;
pay(transaction: PayTransaction): Promise<Response<SuiTransactionResponse>>;
mergeCoin(transaction: MergeCoinTransaction): Promise<Response<SuiTransactionResponse>>;
splitCoin(transaction: SplitCoinTransaction): Promise<Response<SuiTransactionResponse>>;
executeMoveCall(transaction: MoveCallTransaction): Promise<Response<SuiTransactionResponse>>;
publish(transaction: PublishTransaction): Promise<Response<SuiTransactionResponse>>;
transferObjectWithRequestType(transaction: TransferObjectTransaction, requestType?: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
transferSuiWithRequestType(transaction: TransferSuiTransaction, requestType?: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
payWithRequestType(transaction: PayTransaction, requestType?: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
mergeCoinWithRequestType(transaction: MergeCoinTransaction, requestType?: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
splitCoinWithRequestType(transaction: SplitCoinTransaction, requestType?: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
executeMoveCallWithRequestType(transaction: MoveCallTransaction, requestType?: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
publishWithRequestType(transaction: PublishTransaction, requestType?: ExecuteTransactionRequestType): Promise<Response<SuiExecuteTransactionResponse>>;
}
export type IWeb3AptosSDK = {
generateTransaction(payload: Gen.EntryFunctionPayload, options?: Partial<Gen.SubmitTransactionRequest>): Promise<Response<Uint8Array>>; // tx
generateRawTransaction(payload: Uint8Array, extraArgs?: OptionalTransactionArgs): Promise<Response<Uint8Array>>; // tx
generateSignSubmitTransaction(payload: Gen.EntryFunctionPayload, extraArgs?: OptionalTransactionArgs): Promise<Response<Gen.HexEncodedBytes>>; // tx hash
generateSignSubmitRawTransaction(payload: Uint8Array, options?: Partial<Gen.SubmitTransactionRequest>): Promise<Response<Gen.HexEncodedBytes>>; // tx hash
generateSignSubmitWaitForTransaction(payload: Uint8Array, extraArgs?: { maxGasAmount?: BCS.Uint64; gasUnitPrice?: BCS.Uint64; expireTimestamp?: BCS.Uint64; checkSuccess?: boolean; timeoutSecs?: number }): Promise<Response<Gen.Transaction>>; // tx detail
signMessage(message: SignMessagePayload): Promise<Response<SignMessageResponse>>;
simulateTransaction(rawTransaction: Uint8Array, query?: { estimateGasUnitPrice?: boolean; estimateMaxGasAmount?: boolean }): Promise<Response<Gen.UserTransaction[]>>;
signTransaction(rawTransaction: Uint8Array): Promise<Response<Uint8Array>>;
submitTransaction(signedTxn: Uint8Array): Promise<Response<Gen.HexEncodedBytes>>;
signAndSubmitTransaction(rawTransaction: Uint8Array): Promise<Response<Gen.HexEncodedBytes>>;
generateBCSTransaction(rawTransaction: Uint8Array): Promise<Response<Uint8Array>>;
generateBCSSimulation(rawTransaction: Uint8Array): Promise<Response<Uint8Array>>;
submitSignedBCSTransaction(signedTxn: Uint8Array): Promise<Response<Gen.HexEncodedBytes>>;
submitBCSSimulation(bcsBody: Uint8Array, query?: { estimateGasUnitPrice?: boolean; estimateMaxGasAmount?: boolean }): Promise<Response<Gen.UserTransaction[]>>;
getAccount(accountAddress: MaybeHexString): Promise<Response<Gen.AccountData>>;
getAccountTransactions(accountAddress: MaybeHexString, query?: PaginationArgs): Promise<Response<Gen.Transaction[]>>;
getAccountModules(accountAddress: MaybeHexString, query?: { ledgerVersion?: BCS.AnyNumber }): Promise<Response<Gen.MoveModuleBytecode[]>>;
getAccountModule(accountAddress: MaybeHexString, moduleName: string, query?: { ledgerVersion?: BCS.AnyNumber }): Promise<Response<Gen.MoveModuleBytecode>>;
getAccountResources(accountAddress: MaybeHexString, query?: { ledgerVersion?: BCS.AnyNumber }): Promise<Response<Gen.MoveResource[]>>;
getAccountResource(accountAddress: MaybeHexString, resourceType: Gen.MoveStructTag, query?: { ledgerVersion?: BCS.AnyNumber }): Promise<Response<Gen.MoveResource>>;
getEventsByEventKey(eventKey: string): Promise<Response<Gen.Event[]>>;
getEventsByCreationNumber(address: MaybeHexString, creationNumber: BCS.AnyNumber | string, query?: PaginationArgs): Promise<Response<Gen.Event[]>>;
getEventsByEventHandle(address: MaybeHexString, eventHandleStruct: Gen.MoveStructTag, fieldName: string, query?: PaginationArgs): Promise<Response<Gen.Event[]>>;
getTransactions(query?: PaginationArgs): Promise<Response<Gen.Transaction[]>>;
getTransactionByHash(txnHash: string): Promise<Response<Gen.Transaction>>;
getTransactionByVersion(txnVersion: BCS.AnyNumber): Promise<Response<Gen.Transaction>>;
transactionPending(txnHash: string): Promise<Response<boolean>>;
waitForTransactionWithResult(txnHash: string, extraArgs?: { timeoutSecs?: number; checkSuccess?: boolean }): Promise<Response<Gen.Transaction>>;
waitForTransaction(txnHash: string, extraArgs?: { timeoutSecs?: number; checkSuccess?: boolean }): Promise<Response<void>>;
getLedgerInfo(): Promise<Response<Gen.IndexResponse>>;
getChainId(): Promise<Response<number>>;
getTableItem(handle: string, data: Gen.TableItemRequest, query?: { ledgerVersion?: BCS.AnyNumber }): Promise<Response<any>>;
lookupOriginalAddress(addressOrAuthKey: MaybeHexString): Promise<Response<HexString>>;
getBlockByHeight(blockHeight: number, withTransactions?: boolean): Promise<Response<Gen.Block>>;
getBlockByVersion(version: number, withTransactions?: boolean): Promise<Response<Gen.Block>>;
};
Last updated