Provider Methods

Once you have obtained a provider using getProvider(), you can use the following methods:

request

await provider.request({ method, params });

The provider implements the EIP-1193 standard, so you can make JSON-RPC requests using the request method.

The request method sends JSON-RPC requests to the blockchain network. It handles both Wepin-specific wallet methods (like account requests and transaction signing) and standard blockchain RPC calls.

Parameters

  • args <RequestArguments>

    • method <string> - RPC method name

    • params <any[]> optional - Method parameters

Return value

  • Promise<any> - RPC Response

Example

const provider = await wepinProvider.getProvider('ethereum');

// Get connected accounts
const accounts = await provider.request({
  method: 'eth_requestAccounts',
});
console.log('Connected accounts:', accounts);

// Sign message
const signature = await provider.request({
  method: 'eth_sign',
  params: ['0x...', 'Hello, world!'],
});

// Personal sign
const personalSignature = await provider.request({
  method: 'personal_sign',
  params: ['Hello, World', '0x...'],
});

// Sign typed data v4
const typedDataV4 = {
  types: {
    EIP712Domain: [{ name: 'name', type: 'string' }],
    Mail: [{ name: 'contents', type: 'string' }],
  },
  primaryType: 'Mail',
  domain: { name: 'Ether Mail' },
  message: { contents: 'Hello, Bob!' },
};
const typedSignature = await provider.request({
  method: 'eth_signTypedData_v4',
  params: ['0x...', typedDataV4],
});

// Send transaction
const transaction = {
  from: '0x...',
  to: '0x...',
  value: '0x0',
  data: '0x',
};
const txHash = await provider.request({
  method: 'eth_sendTransaction',
  params: [transaction],
});

Last updated

Was this helpful?