# Introduction

<https://chrome.google.com/webstore/detail/fewcha-aptos-wallet/ebfidpplhabeedpnhjnobghokpiioolj>

**Early access** to the dev version **0.4.11**

{% embed url="<https://github.com/fewcha-wallet/dev-versions/releases/tag/v0.4.11>" %}


# Get Started

Start with [Connect](/get-started/connect)


# Connect

## Connect to Fewcha Wallet

To connect to Fewcha Wallet, you simply call this method `window.fewcha.connect()`

```javascript
await window.fewcha.connect();
```

`connect()`: the method will return a Promise that resolves when the user accepts the connection request to the **DApp** website. The response will look like

```json
{
    "method": "connect",
    "status": 200,
    "data": {
        "address": "0x...",
        "publicKey": "0x..."
    }
}
```

{% hint style="info" %}
To  get all methods of **Wallet**, learn more at [**Wallet methods**](/reference/wallet-methods)
{% endhint %}

To use with **TypeScript** support, please learn more at [TypeScript Wrapper](/typescript-wrapper), and use with React Select Wallet Popup, learn more at [React Connect Button](/react-connect-button)

## Disconnecting

```typescript
await window.fewcha.disconnect();
```

and check current status of connect with[Connection](/reference/wallet-methods/connection#isconnected)


# Get data

After connect to the wallet, you can get [Account Data](/reference/wallet-methods/account-data), examples: **balance**, **address**, **network URL**, **network type**... then show it on your website

### getBalance

```typescript
async window.fewcha.getBalance(): Promise<Response<string>>;
```

Response

```typescript
{
    "method": "getBalance",
    "status": 200,
    "data": "4000"
}
```

### account

```typescript
async window.fewcha.account(): Promise<Response<Record<string, string>>>;
```

Response

```typescript
{
    "method": "getCurrentAccount",
    "status": 200,
    "data": {
        "address": "0x...",
        "publicKey": "0x..."
    }
}
```

### getNetworkType

```typescript
async window.fewcha.getNetworkType(): Promise<Response<"Aptos"|"SUI">>;
```

Response

```typescript
{
    "method": "getCurrentAccount",
    "status": 200,
    "data": "Aptos"
}
```

{% hint style="info" %}
This method is a part of [Account Data](/reference/wallet-methods/account-data) methods
{% endhint %}


# Sign and Submit Transaction

And you can integrate more things or your D.app features with [Transactions](/reference/wallet-methods/transactions)methods

{% tabs %}
{% tab title="Aptos" %}

### 1.1. Single signer transaction

1. Generate transaction using[Transactions](/reference/wallet-methods/transactions#generate-transaction)

```javascript
payload = {
    "type": "entry_function_payload",
    "function": "0x1::coin::transfer",
    "type_arguments": ["0x1::aptos_coin::AptosCoin"],
    "arguments": [
        "0x...", // recipient adddress
        "1000", // amount of APT - decimals = 8
    ]
}

rawTransaction = (await fewcha.aptos.generateTransaction(payload)).data;
```

&#x20; 2\.  Then [Transactions](/reference/wallet-methods/transactions#sign-and-submit-transaction)

```javascript
// Simulate transaction before submission (Optional)
simulateRes = (await fewcha.simulateTransaction(rawTransaction)).data;

// Sign then submit
signedTx = (await fewcha.signTransaction(rawTransaction)).data;
txHash = (await fewcha.aptos.submitTransaction(signedTx)).data;

// Or Sign and submit
txHash = (await fewcha.aptos.signAndSubmitTransaction(rawTransaction)).data;
```

### 1.2. Multiple agent transaction

1. Generate transaction using[Transactions](/reference/wallet-methods/transactions#generate-transaction)

```javascript
payload = {
    "type": "entry_function_payload",
    "function": "0x3::token::direct_transfer_script",
    "type_arguments": [],
    "arguments": [
        "0x...", // creator address
        "Fewcha Membership", // token collection
        "Member Level 1", // token name
        "0", // property_version
        "1", // amount of token
    ]
}

// List of secondary addresses
// direct_transfer_script
// 2 signers is required (primary and 1 secondary signer)
secondarySigners = [
    "0x...",
]

options = {
    // Primary signer
    // If not specified, the current connected account will be selected
    "sender": "0x..."
    // Other options...
}

rawMultiAgentTransaction = (await 
    fewcha.aptos.generateMultiAgentTransaction(
        payload, 
        secondarySigners, 
        options
    )
).data;
```

&#x20; 2\.  Get signatures

```javascript
primaryPubKey = (await fewcha.account()).data.publicKey;
primarySignedTx = (await 
    fewcha.aptos.signMultiAgentTransaction(
        rawMultiAgentTransaction
    )
).data;

// Change account to the secondary signers specified from the transaction generation step
secondaryPubKey = (await fewcha.account()).data.publicKey;
secondarySignedTx = (await 
    fewcha.aptos.signMultiAgentTransaction(
        rawMultiAgentTransaction
    )
).data;
```

&#x20; 3\.  Submit (or simulate) transaction

```javascript
// Simulate
simulateRes = (await fewcha.aptos.simulateMultiAgentTransaction(
    rawMultiAgentTransaction, // multiAgentTxn
    [options.sender, ...secondarySigners], // addresses
    [primaryPubKey, secondaryPubKey], // pubKeys
)).data;

// Submit
txnHash = (await fewcha.aptos.submitSignedBCSMultiAgentTransaction(
    rawMultiAgentTransaction, // multiAgentTxn
    [options.sender, ...secondarySigners], // addresses
    [primaryPubKey, secondaryPubKey], // pubKeys
    [primarySignedTx, secondarySignedTx] // signatures
)).data;
```

### 1.3. Multiple signature transaction

1. Collection account public keys and generate multi-sign address

```javascript
firstPubKey = (await fewcha.account()).data.publicKey;
secondPubKey = (await fewcha.account()).data.publicKey;
thirdPubKey = (await fewcha.account()).data.publicKey;

const {address, publicKey} = (await fewcha.aptos.getMultiSignAccount(
    [firstPubKey, secondPubKey, thirdPubKey], // list signer publicKeys
    2 // threshold - the number of signature made the transaction valid
)).data;

```

&#x20; 2\.  Generate transaction using[Transactions](/reference/wallet-methods/transactions#generate-transaction)

```javascript
payload = {
    "type": "entry_function_payload",
    "function": "0x1::coin::transfer",
    "type_arguments": ["0x1::aptos_coin::AptosCoin"],
    "arguments": [
        "0x...", // recipient adddress
        "1000", // amount of APT - decimals = 8
    ]
}

options = {
    // Multi-sign address
    "sender": "0x..."
    // Other options...
}

rawTransaction = (await 
    fewcha.aptos.generateTransaction(
        payload, 
        options
    )
).data;
```

&#x20; 3\.  Get at least **threshold** signatures from the list signers

```javascript
firstSignature = (await fewcha.aptos.signMultiSignTransaction(rawTransaction)).data;
thirdSignature = (await fewcha.aptos.signMultiSignTransaction(rawTransaction)).data;
```

&#x20; 4\.  Submit (or simulate) transaction

<pre class="language-javascript"><code class="lang-javascript">// Simulate transaction before submission (Optional)
simulateRes = (await fewcha.simulateTransaction(rawTransaction)).data;

<strong>txnHash = (await fewcha.aptos.submitSignedBCSMultiSignTransaction(
</strong><strong>    rawTransaction, // Transaction
</strong><strong>    [0,2], // Bitmap - 0 is index of first signer, 2 is index of third signer
</strong><strong>    publicKey, // multi-sign public key we got from step 1
</strong><strong>    [firstSignature, thirdSignature]
</strong><strong>)).data;
</strong></code></pre>

{% endtab %}

{% tab title="SUI" %}

1. Construct transaction payload

```
payload = {
  suiObjectId: "0x...",
  gasBudget: 1000,
  recipient: "0x...",
  amount: 1000
}
```

&#x20;2\.  Submit the transaction

```
response = (await fewcha.sui.transferSui(payload)).data
```

{% endtab %}
{% endtabs %}


# Response Format and Types

### Response Data

Format data of any response

{% tabs %}
{% tab title="Response Type" %}

```typescript
type Response<T> = {
  data: T;
  method: string;
  status: number;
};
```

Example data

```javascript
{
    status: 200, // check at Status codes
    method: "<method name>",
    data: <data>
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Check list of **status** number at [Status codes](/status-codes)
{% endhint %}

### Public Account

{% tabs %}
{% tab title="PublicAccount" %}

```typescript
type PublicAccount = {
  address: string;
  publicKey: string;
};

```

Example data

```json
{
    "address": "0x20364f4121f608f2a09830bc0ab6980fdccff45c2f5df6c41c17f40e511fe80e",
    "publicKey": "0x89a10bded6d812d21299ee129410d53a74f12f91183989c19282fa24ce629b49"
}
```

{% endtab %}
{% endtabs %}

### Other data types

{% tabs %}
{% tab title="Aptos" %}
Other data types will be obtained from [Aptos SDK](https://github.com/fewcha-wallet/aptos-web3/blob/main/packages/web3/src/types.ts#L81)
{% endtab %}

{% tab title="SUI" %}
Other data types will be obtained from [SUI SDK](https://github.com/fewcha-wallet/aptos-web3/blob/main/packages/web3/src/types.ts#L23)
{% endtab %}
{% endtabs %}


# Serializer/Deserializer

{% tabs %}
{% tab title="Aptos" %}
Aptos using Binary Canonical Serialization (BCS) as their data serializer/deserializer.\
For more information, please check the following docs <https://github.com/aptos-labs/bcs>

### Serializer

```typescript
import { TxnBuilderTypes, BCS } from "@fewcha/aptos";

// RawTransaction
const rawTransaction = new TxnBuilderTypes.RawTransaction(
    sender,
    sequence_number,
    payload,
    max_gas_amount,
    gas_unit_price,
    expiration_timestamp_secs,
    chain_id
)
const serializer = new BCS.Serializer();
tx.serialize(serializer);
const serializedTxn = serializer.getBytes() // Uint8Array

```

### Deserializer

```typescript
import { TxnBuilderTypes, BCS } from "aptos";

// RawTransaction
const deserializer = new BCS.Deserializer(serializedTxn);
const rawTransaction = TxnBuilderTypes.RawTransaction.deserialize(d);
```

{% endtab %}

{% tab title="SUI" %}
**Coming soon**
{% endtab %}
{% endtabs %}


# Status codes

<table><thead><tr><th width="150">Status Code</th><th width="264.52111733363495">Mean</th><th>Description</th></tr></thead><tbody><tr><td>200</td><td><strong>Success</strong></td><td></td></tr><tr><td>401</td><td>User <strong>Rejected</strong> the Request</td><td>User cancel a popup</td></tr><tr><td>403</td><td><strong>Forbidden</strong></td><td>Not connect yet, please connect wallet</td></tr><tr><td>500</td><td><strong>Error</strong></td><td>Network error, blockchain error or wallet error</td></tr></tbody></table>


# TypeScript Wrapper

**Fewcha Wallet provider** is added by default `window.fewcha` and you can use direct methods, look like

{% tabs %}
{% tab title="window\.fewcha" %}

```typescript
window.fewcha.signMessage( ...
window.fewcha.aptos.getAccountTransactions(...
window.fewcha.sui.getObjectsOwnedByAddress(...
window.fewcha.token.createCollection(...
```

{% endtab %}
{% endtabs %}

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

```bash
yarn add aptos @fewcha/web3
```

{% tabs %}
{% tab title="@fewcha/web3" %}

<pre class="language-typescript"><code class="lang-typescript">import Web3 from "@fewcha/web3";

const web3 = new Web3();

web3.action.connect();
web3.action.aptos.signMessage(...
<strong>web3.action.aptos.getAccountTransactions(...
</strong>web3.action.sui.signAndExecuteTransaction(...
web3.action.sui.getObjectsOwnedByAddress(...
</code></pre>

{% endtab %}
{% endtabs %}

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>

```typescript
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>>;
};
```


# React Connect Button

### **Install**

```bash
yarn add aptos @fewcha/web3 @fewcha/web3-react
```

### Use

![](https://1926887028-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArok2SPZK1W4KgWMhZzv%2Fuploads%2F2EMCGGqY8DHXab52oB3a%2Fimage.png?alt=media\&token=f24cd853-e2ab-4226-a28c-3c6c5a683a53)

![](https://1926887028-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FArok2SPZK1W4KgWMhZzv%2Fuploads%2F0aNwsPNdwaSrb8QyO2b0%2FScreen%20Shot%202022-08-03%20at%209.25.25%20PM.png?alt=media\&token=f6b79ee4-4531-44bb-b3ae-235159f5eae0)

Add provider

```typescript
import Web3Provider from "@fewcha/web3-react";

root.render(
  <React.StrictMode>
    <Web3Provider>
      <App />
    </Web3Provider>
  </React.StrictMode>,
);
```

Use **web3**

```typescript
import { ConnectWallet, useWeb3 } from "@fewcha/web3-react";

const { account, balance, isConnected, network, fewcha, martian, currentWallet } = useWeb3();

!isConnected && <ConnectWallet type="list" />

fewcha...
fewcha.aptos...
fewcha.sui...
fewcha.token...

```


# Wallet Methods

Supported from Fewcha Wallet prototype version 0.4.0

All methods follow `window.fewcha.<method>`

Includes

* [Connection](/reference/wallet-methods/connection) methods to `connect` and check the connection status
* [Account Data](/reference/wallet-methods/account-data) methods to get account information
* [Transactions](/reference/wallet-methods/transactions) methods to make transactions happen

###


# Connection

### connect

{% tabs %}
{% tab title="window\.fewcha" %}

```typescript
async window.fewcha.connect(): Promise<Response<PublicAccount>>
```

Response

```typescript
{
    "method": "connect",
    "status": 200,
    "data": {
        "address": "0x20364f4121f608f2a09830bc0ab6980fdccff45c2f5df6c41c17f40e511fe80e",
        "publicKey": "0x89a10bded6d812d21299ee129410d53a74f12f91183989c19282fa24ce629b49"
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Learn more about **Response** and **PublicAccount** type at [Response Format and Types](/response-format-and-types)
{% endhint %}

### disconnect

{% tabs %}
{% tab title="window\.fewcha" %}

```typescript
async window.fewcha.disconnect(): Promise<Response<boolean>>
```

Response

```typescript
{
    "method": "disconnect",
    "status": 200,
    "data": true
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Disconnect the current website with the wallet, the website will get status `403`if the website call to legacy methods
{% endhint %}

### isConnected

{% tabs %}
{% tab title="window\.fewcha" %}

```typescript
async window.fewcha.isConnected(): Promise<Response<boolean>>
```

Response

```typescript
{
    "method": "isConnected",
    "status": 200,
    "data": true
}
```

{% endtab %}
{% endtabs %}


# Account Data

### account

{% tabs %}
{% tab title="window\.fewcha" %}

```typescript
async window.fewcha.account(): Promise<Response<PublicAccount>>
```

Response

```typescript
{
    "method": "getCurrentAccount",
    "status": 200,
    "data": {
        "address": "0x20364f4121f608f2a09830bc0ab6980fdccff45c2f5df6c41c17f40e511fe80e",
        "publicKey": "0x89a10bded6d812d21299ee129410d53a74f12f91183989c19282fa24ce629b49"
    }
}
```

{% endtab %}

{% tab title="@fewcha/web3" %}
[TypeScript Wrapper](/typescript-wrapper)

```typescript
async web3.action.account(): Promise<Response<PublicAccount>>
```

Response

```typescript
{
    "method": "getCurrentAccount",
    "status": 200,
    "data": {
        "address": "0x20364f4121f608f2a09830bc0ab6980fdccff45c2f5df6c41c17f40e511fe80e",
        "publicKey": "0x89a10bded6d812d21299ee129410d53a74f12f91183989c19282fa24ce629b49"
    }
}
```

{% endtab %}
{% endtabs %}

### getNetwork

{% tabs %}
{% tab title="window\.fewcha" %}

```typescript
async window.fewcha.getNetwork(): Promise<Response<string>>;
```

Response

```typescript
{
    "method": "getNetwork",
    "status": 200,
    "data": "https://fullnode.devnet.aptoslabs.com"
}
```

{% endtab %}

{% tab title="@fewcha/web3" %}
[TypeScript Wrapper](/typescript-wrapper)

```typescript
async web3.action.getNetwork(): Promise<Response<string>>;
```

Response

```typescript
{
    "method": "getNetwork",
    "status": 200,
    "data": "https://fullnode.devnet.aptoslabs.com"
}
```

{% endtab %}
{% endtabs %}

### getBalance

{% tabs %}
{% tab title="window\.fewcha" %}

```typescript
async window.fewcha.getBalance(): Promise<Response<string>>;
```

Response

```typescript
{
    "method": "getBalance",
    "status": 200,
    "data": "4000"
}
```

{% endtab %}

{% tab title="@fewcha/web3" %}
[TypeScript Wrapper](/typescript-wrapper)

```typescript
async web3.action.getBalance(): Promise<Response<string>>;
```

Response

```typescript
{
    "method": "getBalance",
    "status": 200,
    "data": {
        "0x1::aptos_coin::AptosCoin": "4000",
        "0x8::staked_coin::StakedCoin": "9000"
    }
}
```

{% endtab %}
{% endtabs %}

### getNetworkType

{% tabs %}
{% tab title="window\.fewcha" %}

```typescript
async window.fewcha.getNetworkType(): Promise<Response<"Aptos"|"SUI">>;
```

Response

```typescript
{
    "method": "getNetworkType",
    "status": 200,
    "data": "SUI"
}
```

{% endtab %}
{% endtabs %}


# Transactions

For **Aptos** networks, please check the following [document](/reference/wallet-methods/transactions/aptos-transaction).

For **SUI** networks, we will update the documents as soon as possible.


# Aptos transaction

### 1. Generate Transaction

#### 1.1. Generate Transaction (Single signer)

*Generate transaction from readable **JSON format** payload.*

{% tabs %}
{% tab title="window\.fewcha" %}
**Method type**

```typescript
async generateTransaction(
    payload: EntryFunctionPayload,
    options?: Partial<SubmitTransactionRequest>
): Promise<Response<Uint8Array>>;

type SubmitTransactionRequest = {
    sender: string;
    sequence_number: string; // U64
    max_gas_amount: string; // U64
    gas_unit_price: string; // U64
    expiration_timestamp_secs: string; // U64
    payload: object; // Transaction Payload (entry, script, module_bundle)
    signature: object; // ed25519, multi_ed25519, multi_agent
}

type EntryFunctionPayload = {
    type: string;
    function: string;
    type_arguments: Array<string>;
    arguments: Array<any>;
}
```

**Example request**

```typescript
const receiverAddress = "0xcca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034";
const amount = 1000;

const payload = {
  type: "entry_function_payload",
  function: "0x1::coin::transfer",
  type_arguments: ["0x1::aptos_coin::AptosCoin"],
  arguments: [receiverAddress, amount],
};

const rawTransaction = await window.fewcha.generateTransaction(payload);
```

**Example response**

```typescript
{
    "method": "generateTransaction",
    "status": 200,
    "data": [...]
}
```

Response data: **TxnBuilderTypes.RawTransaction** as **Uint8Array**

Covert **Uint8Array** to **TxnBuilderTypes.RawTransaction** (optional)

```typescript
import { TxnBuilderTypes } from "aptos";

const d = new BCS.Deserializer(rawTransaction.data);
const tx = TxnBuilderTypes.RawTransaction.deserialize(d);

// type of tx is TxnBuilderTypes.RawTransaction
```

{% endtab %}
{% endtabs %}

#### 1.2. Generate Raw Transaction (Single signer)

*Generate **unsigned** transaction from **BCS serialized** payload*

{% tabs %}
{% tab title="window\.fewcha" %}
**Method type**

```typescript
async generateRawTransaction(
    payload: Uint8Array,
    extraArgs?: {
        maxGasAmount?: BCS.Uint64;
        gasUnitPrice?: BCS.Uint64;
        expireTimestamp?: BCS.Uint64
    }
): Promise<Response<Uint8Array>>;
```

**Example request**

```typescript
const receiverAddress = TxnBuilderTypes.AccountAddress.fromHex(
  "0xcca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034",
);
const sendBalance = 1000;

const token = new TxnBuilderTypes.TypeTagStruct(
  TxnBuilderTypes.StructTag.fromString("0x1::aptos_coin::AptosCoin"),
);
const entryFunctionPayload = new TxnBuilderTypes.TransactionPayloadEntryFunction(
  TxnBuilderTypes.EntryFunction.natural(
    "0x1::coin",
    "transfer",
    [token],
    [BCS.bcsToBytes(receiverAddress), BCS.bcsSerializeUint64(sendBalance)],
  ),
);

const s = new BCS.Serializer();
entryFunctionPayload.serialize(s);

const rawTxn = await window.fewcha.generateRawTransaction(s.getBytes());

console.log(rawTxn);
```

**Example response**

```typescript
{
    "method": "generateRawTransaction",
    "status": 200,
    "data": [...]
}
```

Response data: **TxnBuilderTypes.RawTransaction** as **Uint8Array**

Covert **Uint8Array** to **TxnBuilderTypes.RawTransaction** (optional)

```typescript
import { TxnBuilderTypes } from "aptos";

const d = new BCS.Deserializer(txnRequest.data);
const tx = TxnBuilderTypes.RawTransaction.deserialize(d);

// type of tx is TxnBuilderTypes.RawTransaction
```

{% endtab %}
{% endtabs %}

#### 1.3. Generate BCS Transaction (Single signer)

*Generate **signed*** ***BCS serialized** transaction from **BCS serialized** payload. Connected account will sign this **BCS serialized** payload.*

{% tabs %}
{% tab title="window\.fewcha" %}
**Method type**

```typescript
async generateBCSTransaction(
    rawTransaction: Uint8Array
): Promise<Response<Uint8Array>>;
```

**Example request**

```typescript
const receiverAddress = TxnBuilderTypes.AccountAddress.fromHex(
  "0xcca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034",
);
const sendBalance = 1000;

const token = new TxnBuilderTypes.TypeTagStruct(
  TxnBuilderTypes.StructTag.fromString("0x1::aptos_coin::AptosCoin"),
);
const entryFunctionPayload = new TxnBuilderTypes.TransactionPayloadEntryFunction(
  TxnBuilderTypes.EntryFunction.natural(
    "0x1::coin",
    "transfer",
    [token],
    [BCS.bcsToBytes(receiverAddress), BCS.bcsSerializeUint64(sendBalance)],
  ),
);

const s = new BCS.Serializer();
entryFunctionPayload.serialize(s);

const rawTxn = await web3.action.generateRawTransaction(s.getBytes());
if (!parseError(rawTxn.status)) return;

const bcsTxn = await web3.action.generateBCSTransaction(rawTxn.data);

console.log(bcsTxn);
```

**Example response**

```typescript
{
    "method": "generateBCSTransaction",
    "status": 200,
    "data": [...]
}
```

Response data: **TxnBuilderTypes.RawTransaction** as **Uint8Array**

Covert **Uint8Array** to **TxnBuilderTypes.RawTransaction** (optional)

```typescript
import { TxnBuilderTypes } from "aptos";

const d = new BCS.Deserializer(txnRequest.data);
const tx = TxnBuilderTypes.RawTransaction.deserialize(d);

// type of tx is TxnBuilderTypes.RawTransaction
```

{% endtab %}
{% endtabs %}

### 2. Sign Transaction

#### 2.1. Sign and Submit Transaction (Single signer)

{% hint style="info" %}
We **recommend** you use this method
{% endhint %}

{% tabs %}
{% tab title="window\.fewcha" %}
**Method type**

```typescript
async signAndSubmitTransaction(
    rawTransaction: Uint8Array
): Promise<Response<Gen.HexEncodedBytes>>;
```

**Example request**

```typescript
const receiverAddress = "0xcca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034";
const amount = 1000;

const payload = {
  type: "entry_function_payload",
  function: "0x1::coin::transfer",
  type_arguments: ["0x1::aptos_coin::AptosCoin"],
  arguments: [receiverAddress, amount],
};

const rawTransaction = await window.fewcha.generateTransaction(payload);
if (rawTransaction.status !== 200) return;

const txnHash = await window.fewcha.signAndSubmitTransaction(rawTransaction.data);

console.log("txnHash", txnHash);
```

**Example response**

```typescript
{
    "method": "signAndSubmitTransaction",
    "status": 200,
    "data": "0x67d7b7ccee8530659b91ad284ba2c24bd87fb70c5b4411737f4f314826b5cc97"
}
```

{% endtab %}
{% endtabs %}

#### 2.2. Sign Transaction (Single signer)

Sign a transaction and do not submit to the Aptos blockchain.

{% tabs %}
{% tab title="window\.fewcha" %}
**Method type**

```typescript
async signTransaction(
    rawTransaction: Uint8Array
): Promise<Response<Uint8Array>>;
```

**Example request**

```typescript
const receiverAddress = "0xcca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034";
const amount = 1000;

const payload = {
  type: "entry_function_payload",
  function: "0x1::coin::transfer",
  type_arguments: ["0x1::aptos_coin::AptosCoin"],
  arguments: [receiverAddress, amount],
};

const rawTransaction = await window.fewcha.generateTransaction(payload);
if (rawTransaction.status !== 200) return;

const signedTx = await window.fewcha.signTransaction(rawTransaction.data);

console.log("signedTx", signedTx);
```

**Example response**

```typescript
{
    "method": "signTransaction",
    "status": 200,
    "data": [...]
}
```

Response data: **Uint8Array**
{% endtab %}
{% endtabs %}

#### 2.3. Sign Message (Single signer)

{% tabs %}
{% tab title="signMessage" %}

```typescript
export interface SignMessagePayload {
  address?: boolean; // Should we include the address of the account in the message
  application?: boolean; // Should we include the domain of the dapp
  chainId?: boolean; // Should we include the current chain id the wallet is connected to
  message: string; // The message to be signed and displayed to the user
  nonce: string; // A nonce the dapp should generate
}

export interface SignMessageResponse {
  address: string;
  application: string;
  chainId: number;
  fullMessage: string; // The message that was generated to sign
  message: string; // The message passed in by the user
  nonce: string,
  prefix: string, // Should always be APTOS
  signature: string; // The signed full message
}
```

```typescript
async signMessage(message: SignMessagePayload):
    Promise<Response<SignMessageResponse>>
```

{% endtab %}
{% endtabs %}

### 3. Submit Transaction

#### 3.1 Submit Transaction (Single signer)

{% tabs %}
{% tab title="window\.fewcha" %}
**Method type**

```typescript
async submitTransaction(
    signedTxn: Uint8Array
): Promise<Response<Gen.HexEncodedBytes>>
```

**Example request**

```typescript
const receiverAddress = "0xcca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034";
const amount = 1000;

const payload = {
  type: "entry_function_payload",
  function: "0x1::coin::transfer",
  type_arguments: ["0x1::aptos_coin::AptosCoin"],
  arguments: [receiverAddress, amount],
};

const txnRequest = await window.fewcha.generateTransaction(payload);
if (!parseError(txnRequest.status)) return;

const signedTx = await window.fewcha.signTransaction(txnRequest.data);
if (!parseError(signedTx.status)) return;

const txnHash = await window.fewcha.submitTransaction(signedTx.data);
if (!parseError(txnHash.status)) return;

console.log("tx", txnHash);
```

**Example response**

```typescript
{
    "method": "submitTransaction",
    "status": 200,
    "data": "0x4af85fb48400715fda9c4ea9c3f2bad0c1d6995f6aa0be7f5ea6d74d4f5f7682"
}
```

Response data: **Gen.HexEncodedBytes**
{% endtab %}
{% endtabs %}

### 4. Simulate Transaction

Verify if the transaction is valid. You can use this function to estimate gas consumer.

#### 4.1. simulateTransaction (Single Signer, Multi-Sign)

{% tabs %}
{% tab title="window\.fewcha" %}
**Method type**

```typescript
async simulateTransaction(
    rawTransaction: Uint8Array
): Promise<Response<Gen.UserTransaction[]>>
```

**Example request**

```typescript
const receiverAddress = "0xcca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034";
const sendBalance = 1000;

const payload = {
  type: "entry_function_payload",
  function: "0x1::coin::transfer",
  type_arguments: ["0x1::aptos_coin::AptosCoin"],
  arguments: [receiverAddress, sendBalance],
};

const txnRequest = await window.fewcha.generateTransaction(payload);
if (!parseError(txnRequest.status)) return;

const siTx = await window.fewcha.simulateTransaction(txnRequest.data);
if (!parseError(siTx.status)) return;

console.log("siTx", siTx);
```

**Example response**

```typescript
{
    "method": "simulateTransaction",
    "status": 200,
    "data": [
        {
            "version": "19832615",
            "hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "state_change_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "event_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "state_checkpoint_hash": null,
            "gas_used": "51",
            "success": true,
            "vm_status": "Executed successfully",
            "accumulator_root_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "changes": [...],
            "sender": "0x20364f4121f608f2a09830bc0ab6980fdccff45c2f5df6c41c17f40e511fe80e",
            "sequence_number": "12",
            "max_gas_amount": "2000",
            "gas_unit_price": "1",
            "expiration_timestamp_secs": "1661767977",
            "payload": {
                "function": "0x1::coin::transfer",
                "type_arguments": [
                    "0x1::aptos_coin::AptosCoin"
                ],
                "arguments": [
                    "0xcca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034",
                    "1000"
                ],
                "type": "entry_function_payload"
            },
            "signature": {
                "public_key": "0x89a10bded6d812d21299ee129410d53a74f12f91183989c19282fa24ce629b49",
                "signature": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
                "type": "ed25519_signature"
            },
            "events": [
                {
                    "key": "0x030000000000000020364f4121f608f2a09830bc0ab6980fdccff45c2f5df6c41c17f40e511fe80e",
                    "sequence_number": "9",
                    "type": "0x1::coin::WithdrawEvent",
                    "data": {
                        "amount": "1000"
                    }
                },
                {
                    "key": "0x0200000000000000cca3338dfda1b5e9bab0d744c3b50a9a24e3fe55bba48917307e813a4535e034",
                    "sequence_number": "10",
                    "type": "0x1::coin::DepositEvent",
                    "data": {
                        "amount": "1000"
                    }
                }
            ],
            "timestamp": "1661767957293402"
        }
    ]
}
```

Response data: **Gen.UserTransaction\[]** (array of Gen.UserTransaction)
{% endtab %}
{% endtabs %}

Learn more about **response data types** at [Response Format and Types](/response-format-and-types)

### 5. Supported methods

```typescript
generateTransaction(
  payload: Gen.EntryFunctionPayload,
  options?: Partial<Gen.SubmitTransactionRequest>,
): Promise<Uint8Array>;
generateRawTransaction(payload: Uint8Array, extraArgs?: OptionalTransactionArgs): Promise<Uint8Array>;
generateMultiAgentTransaction(
  payload: Gen.EntryFunctionPayload,
  secondarySenders: MaybeHexString[],
  options?: Partial<Gen.SubmitTransactionRequest>,
): Promise<Uint8Array>;
generateSignSubmitTransaction(
  payload: Gen.EntryFunctionPayload,
  extraArgs?: Partial<Gen.SubmitTransactionRequest>,
): Promise<Gen.HexEncodedBytes>;
generateSignSubmitRawTransaction(
  payload: Uint8Array,
  extraArgs?: {
    maxGasAmount?: BCS.Uint64;
    gasUnitPrice?: BCS.Uint64;
    expireTimestamp?: BCS.Uint64;
    checkSuccess?: boolean;
    timeoutSecs?: number;
  },
): Promise<Gen.HexEncodedBytes>;
generateSignSubmitWaitForTransaction(
  payload: Uint8Array,
  extraArgs?: {
    maxGasAmount?: BCS.Uint64;
    gasUnitPrice?: BCS.Uint64;
    expireTimestamp?: BCS.Uint64;
    checkSuccess?: boolean;
    timeoutSecs?: number;
  },
): Promise<Gen.Transaction>;
signMessage(message: SignMessagePayload): Promise<SignMessageResponse>;
signBuffer(buffer: Uint8Array): Promise<HexString>;
simulateTransaction(
  rawTransaction: Uint8Array,
  query?: {
    estimateGasUnitPrice?: boolean;
    estimateMaxGasAmount?: boolean;
    estimatePrioritizedGasUnitPrice: boolean;
  },
): Promise<Gen.UserTransaction[]>;
simulateMultiAgentTransaction(
  multiAgentTxn: Uint8Array,
  addresses: MaybeHexString[],
  publicKeys: MaybeHexString[],
  query?: {
    estimateGasUnitPrice?: boolean;
    estimateMaxGasAmount?: boolean;
    estimatePrioritizedGasUnitPrice?: boolean;
  },
): Promise<Gen.UserTransaction[]>;
signTransaction(rawTransaction: Uint8Array): Promise<Uint8Array>;
signMultiAgentTransaction(rawMultiAgentTransaction: Uint8Array): Promise<Uint8Array>;
signMultiSignTransaction(rawTransaction: Uint8Array): Promise<Uint8Array>;
submitTransaction(signedTxn: Uint8Array): Promise<Gen.HexEncodedBytes>;
submitSignedBCSMultiAgentTransaction(
  multiAgentTxn: Uint8Array,
  addresses: MaybeHexString[],
  publicKeys: MaybeHexString[],
  _signatures: Uint8Array[],
): Promise<Gen.HexEncodedBytes>;
submitSignedBCSMultiSignTransaction(
  rawTxn: Uint8Array,
  bitmap: number[],
  multiSignPubKey: MaybeHexString,
  _signatures: Uint8Array[],
): Promise<Gen.HexEncodedBytes>;
signAndSubmitTransaction(rawTransaction: Uint8Array): Promise<Gen.HexEncodedBytes>;
generateBCSTransaction(rawTransaction: Uint8Array): Promise<Uint8Array>;
generateBCSSimulation(rawTransaction: Uint8Array): Promise<Uint8Array>;
submitSignedBCSTransaction(signedTxn: Uint8Array): Promise<Gen.HexEncodedBytes>;
submitBCSSimulation(
  bcsBody: Uint8Array,
  query?: {
    estimateGasUnitPrice?: boolean;
    estimateMaxGasAmount?: boolean;
    estimatePrioritizedGasUnitPrice: boolean;
  },
): Promise<Gen.UserTransaction[]>;
```


# SUI transaction

Comming soon


# Token (NFT) Methods (Aptos)

All methods follow `window.fewcha.token.<method>`

```typescript
async createCollection(
    name: string,
    description: string,
    uri: string,
    maxAmount?: BCS.AnyNumber
): Promise<Response<string>>;

async createToken(
    collectionName: string,
    name: string,
    description: string,
    supply: number,
    uri: string,
    max?: BCS.AnyNumber,
    royalty_payee_address?: MaybeHexString,
    royalty_points_denominator?: number,
    royalty_points_numerator?: number,
    property_keys?: Array<string>,
    property_values?: Array<string>,
    property_types?: Array<string>
): Promise<Response<string>>;

async offerToken(
    receiver: MaybeHexString,
    creator: MaybeHexString,
    collectionName: string,
    name: string,
    amount: number,
    property_version?: number
): Promise<Response<string>>;
  
async claimToken(
    sender: MaybeHexString,
    creator: MaybeHexString,
    collectionName: string,
    name: string,
    property_version?: number
): Promise<Response<string>>;

async cancelTokenOffer(
    receiver: MaybeHexString,
    creator: MaybeHexString,
    collectionName: string,
    name: string,
    property_version?: number
): Promise<Response<string>>;

async getCollectionData(
    creator: MaybeHexString,
    collectionName: string
): Promise<Response<any>>;

async getTokenData(
    creator: MaybeHexString,
    collectionName: string,
    tokenName: string
): Promise<Response<TokenTypes.TokenData>>;

async getToken(
    creator: MaybeHexString,
    collectionName: string,
    tokenName: string,
    property_version: string
): Promise<TokenTypes.Token>;

async getTokenForAccount(
    account: MaybeHexString,
    tokenId: TokenTypes.TokenId
): Promise<Response<TokenTypes.Token>>;
```


# SDK Get Data Methods

Supported from Fewcha Wallet prototype version 0.4.0

All methods follow `window.fewcha.aptos.<method>` or  `window.fewcha.sui.<method>`

* [Account](/reference/sdk-get-data-methods/account)methods
* [Transaction](/reference/sdk-get-data-methods/transaction)methods
* [Miscellaneous](/reference/sdk-get-data-methods/miscellaneous)methods


# Account

Version 0.4.7

All methods follow `window.fewcha.aptos.<method>` or  `window.fewcha.sui.<method>`

{% tabs %}
{% tab title="Aptos" %}

```javascript

async getAccount(accountAddress: MaybeHexString): Promise<Response<Gen.AccountData>>;
async getAccountTransactions(accountAddress: MaybeHexString, query?: { start?: BigInt | number; limit?: number }): Promise<Response<Gen.Transaction[]>>;
async getAccountModules(accountAddress: MaybeHexString, query?: { ledgerVersion?: BigInt | number }): Promise<Response<Gen.MoveModuleBytecode[]>>;
async getAccountModule(accountAddress: MaybeHexString, moduleName: string, query?: { ledgerVersion?: BigInt | number }): Promise<Response<Gen.MoveModuleBytecode>>;
async getAccountResources(accountAddress: MaybeHexString, query?: { ledgerVersion?: BigInt | number }): Promise<Response<Gen.MoveResource[]>>;
async getAccountResource(accountAddress: MaybeHexString, resourceType: Gen.MoveStructTag, query?: { ledgerVersion?: BigInt | number }): Promise<Response<Gen.MoveResource>>;
async getMultiSignAccount(publicKeys: MaybeHexString[], threshold: number): Promise<PublicAccount>;

```

{% endtab %}

{% tab title="SUI" %}

```javascript
getObjectsOwnedByAddress(address: string): Promise<SuiObjectInfo[]>;
getGasObjectsOwnedByAddress(address: string): Promise<SuiObjectInfo[]>;
getObjectsOwnedByObject(objectId: string): Promise<SuiObjectInfo[]>;
```

{% endtab %}
{% endtabs %}


# Transaction

Version 0.4.7

All methods follow `window.fewcha.aptos.<method>` or  `window.fewcha.sui.<method>`

{% tabs %}
{% tab title="Aptos" %}

```javascript
async getTransactions(query?: { start?: BigInt | number; limit?: number }): Promise<Response<Gen.Transaction[]>>;
async getTransactionByHash(txnHash: string): Promise<Response<Gen.Transaction>>;
async getTransactionByVersion(txnVersion: BigInt | number): Promise<Response<Gen.Transaction>>;
async transactionPending(txnHash: string): Promise<Response<boolean>>;
async waitForTransactionWithResult(txnHash: string, extraArgs?: { timeoutSecs?: number; checkSuccess?: boolean }): Promise<Response<Gen.Transaction>>;
async waitForTransaction(txnHash: string, extraArgs?: { timeoutSecs?: number; checkSuccess?: boolean }): Promise<Response<void>>;
```

{% endtab %}

{% tab title="SUI" %}

```javascript
getTransactionsForObject(objectID: string): Promise<GetTxnDigestsResponse>;
getTransactionsForAddress(addressID: string): Promise<GetTxnDigestsResponse>;
getTransactionWithEffects(digest: string): Promise<SuiTransactionResponse>;
getTransactionWithEffectsBatch(digests: string[]): Promise<SuiTransactionResponse[]>;
```

{% endtab %}
{% endtabs %}


# Miscellaneous

Version 0.4.7

All methods follow `window.fewcha.aptos.<method>` or  `window.fewcha.sui.<method>`

{% tabs %}
{% tab title="Aptos" %}

```javascript
async getEventsByEventKey(eventKey: string): Promise<Response<Gen.Event[]>>;
async getEventsByEventHandle(address: MaybeHexString, eventHandleStruct: Gen.MoveStructTag, fieldName: string, query?: { start?: BigInt | number; limit?: number }): Promise<Response<Gen.Event[]>>;

async getLedgerInfo(): Promise<Response<Gen.IndexResponse>>;
async getChainId(): Promise<Response<number>>;
async getTableItem(handle: string, data: Gen.TableItemRequest, query?: { ledgerVersion?: BigInt | number }): Promise<Response<any>>;
```

{% endtab %}

{% tab title="SUI" %}

```javascript
getEventsBySender(
    sender: string,
    count?: number | undefined,
    startTime?: number | undefined,
    endTime?: number | undefined,
): Promise<SuiEvents>;
getEventsByTransaction(digest: string, count?: number | undefined): Promise<SuiEvents>;
getEventsByModule(
    package_: string,
    module: string,
    count?: number | undefined,
    startTime?: number | undefined,
    endTime?: number | undefined,
): Promise<SuiEvents>;
getEventsByMoveEventStructName(
    moveEventStructName: string,
    count?: number | undefined,
    startTime?: number | undefined,
    endTime?: number | undefined,
): Promise<SuiEvents>;
getEventsByRecipient(
    recipient: ObjectOwner,
    count?: number | undefined,
    startTime?: number | undefined,
    endTime?: number | undefined,
): Promise<SuiEvents>;
```

{% endtab %}
{% endtabs %}


