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.

ThunderCore RPC Methods

TT Wallet uses the window.ethereum.request(args) method to wrap an RPC Call. Please see the Ethereum wiki.

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

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

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

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 implementation of the X25519_XSalsa20_Poly1305 algorithm.

Example

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

Last updated