Actions
The initiateHandshake
and makeRequest
methods accept a list of actions to perform. An Action
can be created using the Web3JsonRPC
class.
Below is a list of supported actions for each method:
Action | RPC method | initiateHandshake | makeRequest |
---|---|---|---|
RequestAccounts | eth_requestAccounts | ✔️ Supported | ✔️ Supported |
SignTransaction | eth_signTransaction | ❌ Not supported | ✔️ Supported |
SendTransaction | eth_sendTransaction | ❌ Not supported | ✔️ Supported |
- | eth_sign | ❌ Not supported | ❌ Not supported |
PersonalSign | personal_sign | ✔️ Supported | ✔️ Supported |
SignTypedDataV3 | eth_signTypedData_v3 | ✔️ Supported | ✔️ Supported |
SignTypedDataV4 | eth_signTypedData_v4 | ✔️ Supported | ✔️ Supported |
SwitchEthereumChain | wallet_switchEthereumChain | ✔️ Supported | ✔️ Supported |
AddEthereumChain | wallet_addEthereumChain | ✔️ Supported | ✔️ Supported |
WatchAsset | wallet_watchAsset | ✔️ Supported | ✔️ Supported |
RequestAccounts
Request that the user provides an account in the form of an Ethereum address.
Parameters
None.
Example
val requestAccounts = Web3JsonRPC.RequestAccounts().action()
Action requestAccounts = new Web3JsonRPC.RequestAccounts().action(false);
PersonalSign
Sign a message by calculating an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))
.
Adding a prefix to the message makes the calculated signature recognisable as an Ethereum specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim.
See personal_sign.
Parameters
Name | Type | Description |
---|---|---|
address | String | Address to sign data with. |
message | String | Message data to sign. |
Example
val personalSign = Web3JsonRPC.PersonalSign(
address = "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
message = "0xdeadbeaf"
).action()
Action personalSign = new Web3JsonRPC.PersonalSign(
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"0xdeadbeaf")
.action(false);
SignTypedDataV3
Sign typed structured data.
See eth_signTypedData_v3.
Parameters
Name | Type | Description |
---|---|---|
address | String | Address to sign data with. |
typedDataJson | String | Typed data to sign. Structured according to the JSON-Schema specified in EIP-712. |
Example
val signTypedDataV3 = Web3JsonRPC.SignTypedDataV3(
address = "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
typedDataJson = typedData
).action()
Action signTypedDataV3 = new Web3JsonRPC.SignTypedDataV3(
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
typedData)
.action(false);
SignTypedDataV4
Sign typed structured data.
See eth_signTypedData_v4.
Parameters
Name | Type | Description |
---|---|---|
address | String | Address to sign data with. |
typedDataJson | String | Typed data to sign. Structured according to the JSON-Schema specified in EIP-712. |
Example
val signTypedDataV4 = Web3JsonRPC.SignTypedDataV4(
address = "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
typedDataJson = typedData
).action()
Action signTypedDataV4 = new Web3JsonRPC.SignTypedDataV4(
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
typedData)
.action(false);
SignTransaction
Sign a transaction that can be submitted to the network at a later time.
See eth_signTransaction.
Parameters
Name | Type | Description |
---|---|---|
fromAddress | String | Address the transaction is sent from. |
toAddress | String | Optional. Address the transaction is sent to. |
weiValue | BigInt | Value for the transaction, in Wei. |
data | String | Compiled code of a contract or the hash of the invoked method signature and encoded parameters. |
nonce | Int | Optional. Nonce of the transaction. Allows for overwriting pending transactions that use an identical nonce. |
gasPriceInWei | BigInt | Optional. Gas price for the transaction, in Wei. |
maxFeePerGas | BigInt | Optional. Maximum fee per unit of gas for the transaction. |
maxPriorityFeePerGas | BigInt | Optional. Maximum priority fee per unit of gas for the transaction. |
gasLimit | BigInt | Optional. Gas limit for the transaction. |
chainId | String | Chain ID for the transaction, as an integer string. |
Example
val signTransaction = Web3JsonRPC.SignTransaction(
fromAddress = "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
toAddress = "0x000000000000000000000000000000000000dEaD",
weiValue = "10000000000000",
data = "0x",
nonce = 1,
gasPriceInWei = "30000000000",
maxFeePerGas = "60000000000",
maxPriorityFeePerGas = "2500000000",
gasLimit = "1000",
chainId = "1"
).action()
Action signTransaction = new Web3JsonRPC.SignTransaction(
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", // fromAddress
"0x000000000000000000000000000000000000dEaD", // toAddress
"10000000000000", // weiValue
"0x", // data
1, // nonce
"30000000000", // gasPriceInWei
"60000000000", // maxFeePerGas
"2500000000", // maxPriorityFeePerGas
"1000", // gasLimit
"1") // chainId
.action(false);
SendTransaction
Send a transaction, or create a contract if the data
field contains code.
See eth_sendTransaction.
Parameters
Name | Type | Description |
---|---|---|
fromAddress | String | Address the transaction is sent from. |
toAddress | String | Optional. Address the transaction is sent to. |
weiValue | BigInt | Value for the transaction, in Wei. |
data | String | Compiled code of a contract or the hash of the invoked method signature and encoded parameters. |
nonce | Int | Optional. Nonce of the transaction. Allows for overwriting pending transactions that use an identical nonce. |
gasPriceInWei | BigInt | Optional. Gas price for the transaction, in Wei. |
maxFeePerGas | BigInt | Optional. Maximum fee per unit of gas for the transaction. |
maxPriorityFeePerGas | BigInt | Optional. Maximum priority fee per unit of gas for the transaction. |
gasLimit | BigInt | Optional. Gas limit for the transaction. |
chainId | String | Chain ID for the transaction, as an integer string. |
Example
val sendTransaction = Web3JsonRPC.SendTransaction(
fromAddress = "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
toAddress = "0x000000000000000000000000000000000000dEaD",
weiValue = "10000000000000",
data = "0x",
nonce = 1,
gasPriceInWei = "30000000000",
maxFeePerGas = "60000000000",
maxPriorityFeePerGas = "2500000000",
gasLimit = "1000",
chainId = "1"
).action()
Action sendTransaction = new Web3JsonRPC.SendTransaction(
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", // fromAddress
"0x000000000000000000000000000000000000dEaD", // toAddress
"10000000000000", // weiValue
"0x", // data
1, // nonce
"30000000000", // gasPriceInWei
"60000000000", // maxFeePerGas
"2500000000", // maxPriorityFeePerGas
"1000", // gasLimit
"1") // chainId
.action(false);
SwitchEthereumChain
Switch a wallet’s currently active chain.
See wallet_switchEthereumChain.
Parameters
Name | Type | Description |
---|---|---|
chainId | String | ID of the chain to switch to, as an integer string. |
Example
val switchEthereumChain = Web3JsonRPC.SwitchEthereumChain(
chainId = "1666600000"
).action()
Action switchEthereumChain = new Web3JsonRPC.SwitchEthereumChain(
"1666600000") // chainId
.action(false);
AddEthereumChain
Add a chain to a wallet.
Parameters
Name | Type | Description |
---|---|---|
chainId | String | ID of the chain to add, as an integer string. |
blockExplorerUrls | List<String> | Optional. List of block explorer URL strings. |
chainName | String | Optional. Name of the chain to add. |
iconUrls | List<String> | Optional. List of image icons URL strings. |
nativeCurrency | AddChainNativeCurrency | Optional. Data for the chain’s native currency. |
rpcUrls | List<String> | List of RPC URL strings. Defaults to an empty list. |
Example
val addEthereumChain = Web3JsonRPC.AddEthereumChain(
chainId = "1666600000",
blockExplorerUrls = listOf("https://explorer.harmony.one"),
chainName = "Harmony Mainnet",
iconUrls = listOf("https://harmonynews.one/wp-content/uploads/2019/11/slfdjs.png"),
nativeCurrency = AddChainNativeCurrency("ONE", "ONE", 18)
).action()
Action addEthereumChain = new Web3JsonRPC.AddEthereumChain(
"1666600000", // chainId
List.of("https://explorer.harmony.one"), // blockExplorerUrls
"Harmony Mainnet", // chainName
List.of("https://harmonynews.one/wp-content/uploads/2019/11/slfdjs.png"), // iconUrls
new AddChainNativeCurrency("ONE", "ONE", 18)) // nativeCurrency
.action(false);
WatchAsset
Add and track a new asset within a wallet.
See wallet_watchAsset.
Parameters
Name | Type | Description |
---|---|---|
type | String | Type of token asset. (i.e. ERC20 , ERC721 ). |
options | WatchAssetOptions | Data of the asset to watch (i.e. contract address, name, icon, etc.) |
Example
val watchAsset = Web3JsonRPC.WatchAsset(
type = "ERC20",
options = WatchAssetOptions(
"0xcf664087a5bb0237a0bad6742852ec6c8d69a27a",
"WONE",
18,
"https://s2.coinmarketcap.com/static/img/coins/64x64/11696.png"
)
).action()
Action watchAsset = new Web3JsonRPC.WatchAsset(
"ERC20", // type
new WatchAssetOptions( // options
"0xcf664087a5bb0237a0bad6742852ec6c8d69a27a", // address
"WONE", // symbol
18, // decimals
"https://s2.coinmarketcap.com/static/img/coins/64x64/11696.png") // image
).action(false);
Types
AddChainNativeCurrency
Defines a native currency to add when making a request to add a new Ethereum chain.
See AddEthereumChain.
Properties
Name | Type | Description |
---|---|---|
name | String | Name of native currency for the chain. |
symbol | String | Symbol of native currency for the chain. |
decimals | Int | Decimals of precision, as an integer. |
Example
val nativeCurrency = AddChainNativeCurrency("ONE", "ONE", 18)
AddChainNativeCurrency nativeCurrency = new AddChainNativeCurrency("ONE", "ONE", 18);
WatchAssetOptions
Defines options when making a request to watch a new asset.
See WatchAsset.
Properties
Name | Type | Description |
---|---|---|
address | String | Contract address for the token asset. |
symbol | String | Optional. Symbol for the token asset. |
decimals | Int | Optional. Decimals of precision, as an integer. |
image | String | Optional. Logo image for the token asset. |
Example
val watchAssetOptions = WatchAssetOptions(
address = "0xcf664087a5bb0237a0bad6742852ec6c8d69a27a",
symbol = "WONE",
decimals = 18,
image = "https://s2.coinmarketcap.com/static/img/coins/64x64/11696.png"
)
WatchAssetOptions watchAssetOptions = new WatchAssetOptions(
"0xcf664087a5bb0237a0bad6742852ec6c8d69a27a", // address
"WONE", // symbol
18, // decimals
"https://s2.coinmarketcap.com/static/img/coins/64x64/11696.png") // image
);