Ethereum Jsonrpc API
Ethereum Jsonrpc API for the Wallet SDK.
#
eth_requestAccountsRequest access to the user's Ethereum account in order to interact with the blockchain, sign transactions, or perform other operations.
The request will trigger a prompt in the Binance app asking the user to grant the requested account(s) access to the DApp. If the user approves the request, the API will return a promise that resolves to an array of Ethereum account addresses that have been granted access.
#
Parameters[]
#
Returnsstring[]
: An array of Ethereum account addresses.
#
Example#
eth_accountsRequest the available accounts.
This API call does not request user permission or access to Ethereum accounts. Instead, it returns an array of Ethereum account addresses that are available to the currently connected Ethereum node.
#
Parameters[]
#
Returnsstring[]
: An array of Ethereum account addresses.
#
Example#
eth_chainIdRetrieve the chain ID of the currently connected Ethereum network. 0x0
will be returned use default value.
#
Parameters[]
#
Returnsstring
: Hexadecimal encoded value.
#
Example#
eth_signTransactionRequest the user to sign a transaction that can be submitted to the network at a later time using eth_sendRawTransaction
.
#
ParametersEthTransaction
#
Returnsstring
: Signed signature
#
Example#
eth_sendTransactionRequest the user to sign and send the transaction to the blockchain. Return a promise that resolves the transaction hash.
It 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.
#
ParametersEthTransaction
#
Returnsstring
: Transaction hash which starts with '0x' prefix.
#
Example#
eth_signThe sign method calculates an Ethereum-specific signature with the following: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))).
Adding a prefix to the message makes the calculated signature recognizable as an Ethereum-specific signature. This prevents misuse where a malicious Dapp could sign arbitrary data (e.g., a transaction) and use the signature to impersonate the victim.
Note: This method will deprecate in the future due to potential security risks.
#
ParametersAddress
, Message
#
Returnsstring
: Signature
#
Example#
personal_signThe sign method calculates an Ethereum-specific signature with the following: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))). This is the recommended method for signing messages on the DApp side.
Adding a prefix to the message makes the calculated signature recognizable as an Ethereum-specific signature. This prevents misuse where a malicious Dapp can sign arbitrary data (e.g., a transaction) and use the signature to impersonate the victim.
Note: See ecRecover
to verify the signature.
#
ParametersMessage
, Address
#
Returnsstring
: Signature
#
Example#
eth_signTypedDataCalculates an Ethereum-specific signature in the form of keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))
Adding a prefix to the message makes the calculated signature recognizable as an Ethereum-specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g., a transaction) and use the signature to impersonate the victim.
#
ParametersAddress
, TypedData
Address
, 20 Bytes - address.TypedData
, N Bytes - message to sign containing type information, a domain separator, and data
#
Returnsstring
: Signature
#
Example#
wallet_switchEthereumChainPrompt the user to switch to the new network. It returns a promise that resolves when the user has switched to the new network or rejects it with an error if the user cancels the switch or the switch is unsuccessful.
#
ParametersSwitchEthereumChainParameter
#
Chain IDsThese are the IDs of the Ethereum chains that Wallet SDK supports by default
Network | Chain ID |
---|---|
BNB Chain Mainnet | 0x38 |
Ethereum Mainnet | 0x1 |
#
Returnsnull
: Null will be returned if switch successfully
#
Example#
wallet_watchAssetRequest the user to add a token to the Binance Defi Wallet. It returns a promise that resolves when the user has added the asset to the wallet or rejects it with an error if the user cancels the operation or the operation is unsuccessful.
Only the token address is required when requested; the wallet will determine the token symbol and token decimals automatically.
Note: Currently, Binance Defi Wallet only supports ERC20 tokens. Other standards will be supported in the future.
#
ParametersWatchAssetParameter
#
Returnsboolean
: true
if the the token was added, false
otherwise.