# Ethereum Provider API

## Summary

TT Wallet injects a global API into site visited by its users at `window.ethereum`.

Considering the massive adoption, this API specification borrows heavily from Metamask's documents. So Dapp developers can easily request users's ThunderCore's accounts, read data from blockchians, and prompt the users to sign data and send transactions.

The Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193).

## ThunderCore RPC Methods

TT Wallet uses the `window.ethereum.request(args)` method to wrap an RPC Call. Please see the [Ethereum wiki](https://eth.wiki/json-rpc/API#json-rpc-methods).

Important methods from this API include:

* `eth_acccounts`
* `eth_requestAccounts`
* `eth_call`
* `eth_getBalance`
* `eth_sendTransaction`
* `eth_decrypt`
* `eth_getEncryptionPublicKey`
* `eth_sign`
* `personal_sign`
* `eth_signTypedData`
* `eth_signTypedData_v3`
* `eth_signTypedData_v4`
* `personal_ecRecover`

### Interface

```typescript
interface RequestArguments {
    method: string;
    params: unknown[] | object;
};

window.ethereum.request(args: RequestArguments): Promise<unknown>;
```

### `eth_requestAccounts`

#### Returns

`string[]` - An array of a single, hexadecimal ThunderCore address string.

#### Description

Requests that the user provides an ThunderCore address to be identified by. Returns a Promise that resolves to an array of a single ThunderCore address string.

#### Example

```javascript
window.ethereum
  .request({ method: "eth_requestAccounts" })
  .then((accounts) => {})
  .catch((error) => {});
```

## Other RPC Methods

### `eth_decrypt`

#### Parameters

* `Array`
  1. `string` - An encrypted message.
  2. `string` - The address of the ThunderCore account that can decrypt the message.

#### Description

Requests that TT Wallet decrypts the given encrypted message. The message must have been encrypted using the public encryption key of the given ThunderCore address. Returns a Promise that resolves to the decrypted message, or rejects if the decryption attempt fails.

#### Example

```javascript
window.ethereum
  .request({
    method: "eth_decrypt",
    params: [encryptedMessage, accounts[0]],
  })
  .then((decryptedMessage) => {})
  .catch((error) => {});
```

### `eth_getEncryptionPublicKey`

#### Parameters

* `Array`
  1. `string` - The address of the ThunderCore account whose encryption key should be retrieved.

#### Returns

`string` - The public encryption key of the specified ThunderCore account.

#### Description

Requests that the user shares their public encryption key. Returns a Promise that resolve to the public encryption key, or rejects if the user denied the request.

The public key is computed from entropy associated with the specified user account, using the [`nacl`](https://github.com/dchest/tweetnacl-js) implementation of the `X25519_XSalsa20_Poly1305` algorithm.

#### Example

```javascript
window.ethereum
  .request({
    method: "eth_getEncryptionPublicKey",
    params: [accounts[0]],
  })
  .then((result) => {})
  .catch((error) => {});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.developers.thundercore.com/develop-on-tt-wallet/ethereumproviderapi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
