Ethereum Provider
Ethereum Provider for the Wallet SDK.
#
Initialization#
Establish Connectionconnect
#
DescriptionRequest the user to approve the connection between the DApp and the Binance Defi Wallet. Return a promise that resolves the approved account list. If the user denies the request, the promise will be rejected with a 100001
or 100002
error code.
#
Error code100001
: User closed connection modal at dApp side
100002
: User rejected connection at Binance app side
100003
: Provider is not ready
100004
: Already processing the connection request
100005
: Already connected
#
Example#
Sign Messageeth_sign
| personal_sign
| eth_signTypedData
| eth_signTypedData_v1
| eth_signTypedData_v2
| eth_signTypedData_v3
| eth_signTypedData_v4
#
DescriptionRequest the user to sign the message or typed data with a private key. Return a promise that resolves the signature. If the user denies the request, the promise will be rejected with a 200001
error code.
#
Error code200001
: User rejected sign the information
200004
: Invalid sign param
#
Example#
Send Transactioneth_sendTransaction
#
DescriptionRequest the user to sign and send the transaction to the blockchain. Return a promise that resolves the transaction hash.
This promise is used to transfer native tokens or to interact with smart contracts deployed on the blockchain. Once a user initiates the transaction, it is broadcast to the blockchain and processed by nodes on the network. Miners then compete to include the transaction in the next block on the blockchain. Once the transaction is confirmed and included in a block, the transfer of Ether or interaction with the smart contract is executed, and the transaction is considered complete.
#
Error code200001
: User rejected sign the information
200004
: Invalid sign param
#
Example#
Disconnectdisconnect
#
DescriptionDisconnect the connection between the DApp and Binance Defi Wallet proactively. A disconnect
event will be emitted.
#
Example#
EventsThe SDK provides a similar events API to eventemitter3. It allows DApp developers to receive real-time updates about certain actions that have taken place on the Binance Defi Wallet, which can then be used to trigger further actions within the DApp.
It is important to note that developers should always unsubscribe from events when they are no longer needed to prevent unnecessary resource usage. This can be done using the ‘off’ method provided by the SDK.
#
accountsChangedTriggered when there is an account change in the Binance Defi Wallet accounts. This event is emitted as an array of the current accounts held.
Developers can listen for the accountsChanged
event using the provider's ‘on’ method, passing the event name as the first argument and a callback function as the second argument. When the event is triggered, the callback function will be initiated with the new array of accounts as the only parameter.
It is important to note that the accountsChanged
event is not triggered when the DApp initially connects to the wallet but only when there is a subsequent change in the connected accounts.
#
chainChangedTriggered when there is a change in the Binance Defi Wallet's network chain. This event is emitted as a string containing the updated chain ID.
Developers can listen for the chainChanged
event using the provider's ‘on’ method, passing the event name as the first argument and a callback function as the second argument. When the event is triggered, the callback function will be called with the new chain ID as the only parameter.
It is important to note that the chainChanged
event is not triggered when the DApp initially connects to the wallet but only when there is a subsequent change in the connected network chain.
#
disconnectTriggered when the connection between the DApp and Binance Defi Wallet is terminated. This event is emitted with the disconnect
type.
Developers can listen for the disconnect
event using the provider's ‘on’ method, passing the event name as the first argument and a callback function as the second argument. When the event is triggered, the callback function will be called with the disconnect
type.