Biport 월렛 가이드
  • Overview
  • ⛳온보딩 프로세스
    • 바이포트 지갑 설치하기
    • 새 지갑 만들기
    • 기존 지갑 가져오기
  • 💡바이포트 사용 튜토리얼
    • 친구에게 자산 전송하기
    • 홈 화면에 토큰 추가하기
    • 스마트컨트랙트 전송 방지하기
    • 메타마스크 지원 기능 이용하기
    • BiFi에 예금하기
  • 🖨️API Documentation
    • 시작하기
      • Biport 감지하기
      • 사용자의 네트워크 감지하기
      • 사용자의 계정 접근하기
    • API
      • Biport provider API
      • JSON-RPC API
  • ❓서포트
    • Audit
    • 고객센터
    • English
    • 모바일 가이드
Powered by GitBook
On this page

Was this helpful?

  1. API Documentation
  2. 시작하기

사용자의 계정 접근하기

사용자에게서 서명을 요청하거나 사용자가 트랜잭션을 승인하도록하려면 eth_requestAccounts RPC 방법을 사용하여 사용자의 계정에 액세스해야 합니다.

const accounts = await window.biport.request({ method: 'eth_requestAccounts' })
  .catch((err) => {
    if (err.code === 4001) {
      // EIP-1193 userRejectedRequest error
      // If this happens, the user rejected the connection request.
      console.log('Please connect to Biport.');
    } else {
      console.error(err);
    }
  });

console.log('Connected Account:', accounts[0]);

사용자 계정 다루기

eth_accounts RPC 메소드를 사용하여 사용자 계정을 다룰 수 있습니다. provider에서 accountsChanged 이벤트를 수신하여 사용자 계정이 변경될 때 알림을 받을 수 있습니다.

let currentAccount = null;
window.biport.request({ method: 'eth_accounts' })
  .then(handleAccountsChanged)
  .catch((err) => {
    // Some unexpected error.
    // For backwards compatibility reasons, if no accounts are available,
    // eth_accounts returns an empty array.
    console.error(err);
  });

// Note that this event is emitted on page load.
// If the array of accounts is non-empty, you're already
// connected.
window.biport.on('accountsChanged', handleAccountsChanged);

// eth_accounts always returns an array.
function handleAccountsChanged(accounts) {
  if (accounts.length === 0) {
    // Biport is locked or the user has not connected any accounts.
    console.log('Please connect to Biport.');
  } else if (accounts[0] !== currentAccount) {
    // Reload your interface with accounts[0].
    currentAccount = accounts[0];
    // Update the account displayed (see the HTML for the connect button)
    showAccount.innerHTML = currentAccount;
  }
}
Previous사용자의 네트워크 감지하기NextAPI

Last updated 2 years ago

Was this helpful?

🖨️