EIP1193 - Provider (WIP)

This page will describe how to construct an EIP1193 provider using Tria SDK.

Initialization

A dApp can integrate the Tria SDK and construct the Tria provider to connect to any chain and perform transactions and contract calls.

const provider = new TriaProvider({
    config,
    authUrl,
    dappDomain,
    dappLogo,
    aa,
    environment,
});

Params

  • config (optional) -

  • authUrl (optional) -

  • dappDomain (optional) - The hostname/domain of the dApp. eg. https://opensea.io

  • dappLogo (optional) - The logo of the dApp to be displayed in the wallet. eg. https://your-dapp-logo.com

  • environment (optional - string) - The runtime environment. "testnet", "mainnet-staging", "mainnet"

  • aa (optional) - This is an object with the Account Abstraction params

    • supportAa (boolean) - If the dApp wants to enable Account Abstraction smart wallets

    • pimlicoApiKey (optional - string) - The dApp can pass their pimlico api key

    • isSponsored (optional - boolean) - Indicate whether the dApp wants to support sponsored transactions

    • sponsorshipPolicyId (optional - string) -

    • accountType (optional - string) - The type of smart wallet to be created. Options - "Simple", "Kernel", "Safe", "Biconomy", "Etherspot"

    • sponsorshipPolicyIds (optional - string) -

This provider can be used to perform any transactions or request for connected accounts, etc.

Methods

The request should be a standard JSON-RPC payload, which should at a minimum specify the method and params

Get Accounts

const accounts = await provider.request({
    method: 'eth_accounts',
});

This will return the connected account in an array.

Get Network and Chain ID

const chainId = await provider.request({
    method: 'eth_chainId',
});

const networkId = await provider.request({
    method: 'net_version',
});

Any request that requires user's consent/approval will trigger a wallet open.

Send Transaction

const result = await provider.request({
  method: 'eth_sendTransaction',
  params: [
    {
      from: accounts[0],
      to: recipientAddress,
      value,
      gasLimit: '0x5028',
      maxFeePerGas: '0x2540be400',
      maxPriorityFeePerGas: '0x3b9aca00',
    },
  ],
});

This method will open the wallet with all the provided wallet information. Once the user signs the transaction, it will be broadcasted and responds with a transaction hash.

Sign Message

eth_sign and personal_sign opens up the wallet with the message.

eth_sign

const exampleMessage = 'Hello World';

const msg = `0x${Buffer.from(exampleMessage, 'utf8').toString('hex')}`;

const ethResult = await provider.request({
  method: 'eth_sign',
  params: [accounts[0], msg],
});

personal_sign

const exampleMessage = 'Hello World';

const msg = `0x${Buffer.from(exampleMessage, 'utf8').toString('hex')}`;

const sign = await provider.request({
    method: 'personal_sign',
    params: [msg, accounts[0]],
});

Last updated