Biport는 window.biport.request(args)
provider method를 사용하여 JSON-RPC API를 래핑합니다.
표준 Ethereum RPC 메소드에 대한 자세한 내용은 를 참조하십시오.
아래는 RPC 메소드 중 eth_chainId
로 호출하는 예제입니다.
window.biport.request({ method: 'eth_chainId' })
.then((chainId) => {
console.log('Response:', chainId);
}).catch((error) => {
if (error.code === 4001) {
// EIP-1193 userRejectedRequest error
console.log('Please connect to MetaMask.');
} else {
console.error(error);
}
});
를 참조하여 window.biport.request(args)
를 사용하세요.
Methods
wallet_getPermissions
요청자에게 현재 지갑의 권한 정보들을 가져옵니다.
window.biport.request({ method: 'wallet_getPermissions' })
.then((result) => {
console.log('Response:', result);
});
지갑에서 DApp과 연결된 권한의 정보입니다. 요청자가 권한을 가지고 있지 않은 경우, 결과의 배열은 비어 있습니다.
wallet_requestPermissions
사용자로부터 권한을 요청합니다. 현재 eth_accounts 만 권한 요청이 필요합니다.
이 요청은 Biport 팝업을 트리거합니다. 권한을 요청하는 것은 사용자의 직접적인 액션(버튼 클릭 등)에 대한 응답으로만 요청해야 합니다.
window.biport
.request({
method: 'wallet_requestPermissions',
params: [{ eth_accounts: {} }],
})
.then((permissions) => {
const accountsPermission = permissions.find(
(permission) => permission.parentCapability === 'eth_accounts'
);
if (accountsPermission) {
console.log('eth_accounts permission successfully requested!');
}
})
.catch((error) => {
if (error.code === 4001) {
// EIP-1193 userRejectedRequest error
console.log('Permissions needed to continue.');
} else {
console.error(error);
}
});
wallet_switchEthereumChain
지정된 체인 ID를 가진 체인으로 전환하도록 사용자에게 확인 메시지를 만듭니다.
이 메소드는 사용자의 직접적인 액션(버튼 클릭 등)에 대한 응답으로만 호출해야 합니다.
다음 중 하나라도 해당되는 경우, Biport는 요청을 거부합니다.
지정된 체인 ID를 가진 체인을 Biport가 지원하지 않음
이 메소드는 EIP-3326에 의해 정의됩니다.
await biport.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x5' }],
});
wallet_watchAsset
이 메서드는 사용자가 Biport에서 지정된 토큰을 추적하도록 요청합니다.
이 메서드는 dapp 개발자가 런타임에서 사용자에게 지갑에서 토큰을 추적하도록 요청할 수 있도록 합니다.
이 메서드는 EIP-747에 의해 지정됩니다.
biport
.request({
method: 'wallet_watchAsset',
params: {
type: 'ERC20',
options: {
address: '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
symbol: 'FOO',
decimals: 18,
image: 'https://foo.io/token-image.svg',
},
},
})
.then((success) => {
if (success) {
console.log('FOO successfully added to wallet!');
} else {
throw new Error('Something went wrong.');
}
})
.catch(console.error);
지원하지 않는 Methods
wallet_registerOnboarding
위 RPC Method는 현재 지원하지 않습니다.