Skip to main content

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:

ActionRPC methodinitiateHandshakemakeRequest
RequestAccountseth_requestAccounts✔️ Supported✔️ Supported
SignTransactioneth_signTransaction❌ Not supported✔️ Supported
SendTransactioneth_sendTransaction❌ Not supported✔️ Supported
-eth_sign❌ Not supported❌ Not supported
PersonalSignpersonal_sign✔️ Supported✔️ Supported
SignTypedDataV3eth_signTypedData_v3✔️ Supported✔️ Supported
SignTypedDataV4eth_signTypedData_v4✔️ Supported✔️ Supported
SwitchEthereumChainwallet_switchEthereumChain✔️ Supported✔️ Supported
AddEthereumChainwallet_addEthereumChain✔️ Supported✔️ Supported
WatchAssetwallet_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

NameTypeDescription
addressStringAddress to sign data with.
messageStringMessage 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

NameTypeDescription
addressStringAddress to sign data with.
typedDataJsonStringTyped 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

NameTypeDescription
addressStringAddress to sign data with.
typedDataJsonStringTyped 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

NameTypeDescription
fromAddressStringAddress the transaction is sent from.
toAddressStringOptional. Address the transaction is sent to.
weiValueBigIntValue for the transaction, in Wei.
dataStringCompiled code of a contract or the hash of the invoked method signature and encoded parameters.
nonceIntOptional. Nonce of the transaction. Allows for overwriting pending transactions that use an identical nonce.
gasPriceInWeiBigIntOptional. Gas price for the transaction, in Wei.
maxFeePerGasBigIntOptional. Maximum fee per unit of gas for the transaction.
maxPriorityFeePerGasBigIntOptional. Maximum priority fee per unit of gas for the transaction.
gasLimitBigIntOptional. Gas limit for the transaction.
chainIdStringChain 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

NameTypeDescription
fromAddressStringAddress the transaction is sent from.
toAddressStringOptional. Address the transaction is sent to.
weiValueBigIntValue for the transaction, in Wei.
dataStringCompiled code of a contract or the hash of the invoked method signature and encoded parameters.
nonceIntOptional. Nonce of the transaction. Allows for overwriting pending transactions that use an identical nonce.
gasPriceInWeiBigIntOptional. Gas price for the transaction, in Wei.
maxFeePerGasBigIntOptional. Maximum fee per unit of gas for the transaction.
maxPriorityFeePerGasBigIntOptional. Maximum priority fee per unit of gas for the transaction.
gasLimitBigIntOptional. Gas limit for the transaction.
chainIdStringChain 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

NameTypeDescription
chainIdStringID 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.

See wallet_addEthereumChain.

Parameters

NameTypeDescription
chainIdStringID of the chain to add, as an integer string.
blockExplorerUrlsList<String>Optional. List of block explorer URL strings.
chainNameStringOptional. Name of the chain to add.
iconUrlsList<String>Optional. List of image icons URL strings.
nativeCurrencyAddChainNativeCurrencyOptional. Data for the chain’s native currency.
rpcUrlsList<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

NameTypeDescription
typeStringType of token asset. (i.e. ERC20, ERC721).
optionsWatchAssetOptionsData 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

NameTypeDescription
nameStringName of native currency for the chain.
symbolStringSymbol of native currency for the chain.
decimalsIntDecimals 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

NameTypeDescription
addressStringContract address for the token asset.
symbolStringOptional. Symbol for the token asset.
decimalsIntOptional. Decimals of precision, as an integer.
imageStringOptional. 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
);