连接至 SBTAuth 钱包
本文档帮助您连接至 SBTAuth 钱包。
SBTAuth 提供标准的 EIP1193 Provider API。
1. 获取钱包 Provider
如果已经通过 sbtauth 登录,可以从 sbtauth.provider 获取 provider。
// 从 sbtauth 获取钱包 Providerconst provider = sbtauth.provder
2. 使用 Ethers.js
// 获取余额const provider = new ethers.providers.Web3Provider(sbtauth.provider)const address = sbtauth.provider.accounts[0]const balance = await provider.getalance(address)
3. 消息签名
// 消息签名const provider = new ethers.providers.Web3Provider(sbtauth.provider)const signer = provider.getSigner()const signature = await signer.signMessage('Test messsage')
4. 发送交易
示例为 Erc20 token 的转账。
const provider = new ethers.providers.Web3Provider(sbtauth.provider)const signer = provider.getSigner()const abi = [ 'function transfer(address to, uint amount) returns (bool)', 'event Transfer(address indexed from, address indexed to, uint amount)',]const address = '0xff04b6fBd9FEcbcac666cc0FFfEed58488c73c7B'const erc20 = new ethers.Contract(address, abi, signer)await erc20.transfer('ricmoo.eth', ethers.utils.parseUnits('1.23'))
5. 其他 RPC 接口
eth_decrypt
示例
const decryptedMessage = await sbtauth.provider.request({ method: 'eth_decrypt', params: [message] })
eth_getEncryptionPublicKey
示例
const encryptionPublicKey = await sbtauth.provider.request({ method: 'eth_getEncryptionPublicKey' })
Table of Contents