프로바이더 메서드

`getProvider()`를 사용하여 프로바이더를 얻은 후에는, 다음 메서드들을 사용할 수 있습니다:

request

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

해당 프로바이더는 EIP-1193 표준을 구현하고 있으므로, request 메서드를 사용하여 JSON-RPC 요청을 보낼 수 있습니다. request 메서드는 블록체인 네트워크로 JSON-RPC 요청을 전송하며, 계정 요청이나 트랜잭션 서명과 같은 Wepin 전용 지갑 메서드뿐만 아니라, 표준 블록체인 RPC 호출도 처리할 수 있습니다.

Parameters

  • args <RequestArguments>

    • method <string> - RPC 메서드 이름

    • params <any[]> optional - 메서드에 전달할 파라미터

Return value

  • Promise<any> - RPC 반환값

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?