Guides
DocumentationLog In

API Reference

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

let requestAccounts = Action(jsonRpc: .eth_requestAccounts)

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

let personalSign =
      Action(jsonRpc: .personal_sign(
            address: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
            message: "0xdeadbeaf"))

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

let signTypedDataV3 =
      Action(jsonRpc: .eth_signTypedData_v3(
            address: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
            typedDataJson: JSONString(encode: typedData)!))

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

let signTypedDataV4 =
      Action(jsonRpc: .eth_signTypedData_v4(
            address: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
            typedDataJson: JSONString(encode: typedData)!))

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

let signTransaction = 
      Action(jsonRpc: .eth_signTransaction(
             fromAddress: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
             toAddress: "0x000000000000000000000000000000000000dEaD",
             weiValue: "10000000000000",
             data: "0x",
             nonce: 1,
             gasPriceInWei: "30000000000",
             maxFeePerGas: "60000000000",
             maxPriorityFeePerGas: "2500000000",
             gasLimit: "1000",
             chainId: "1"))

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

let sendTransaction = 
      Action(jsonRpc: .eth_sendTransaction(
             fromAddress: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
             toAddress: "0x000000000000000000000000000000000000dEaD",
             weiValue: "10000000000000",
             data: "0x",
             nonce: 1,
             gasPriceInWei: "30000000000",
             maxFeePerGas: "60000000000",
             maxPriorityFeePerGas: "2500000000",
             gasLimit: "1000",
             chainId: "1"))

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

let switchEthereumChain =
      Action(jsonRpc: .wallet_switchEthereumChain(chainId: "1666600000"))

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

let addEthereumChain = 
      Action(jsonRpc: .wallet_addEthereumChain(
             chainId: "1666600000",
              blockExplorerUrls: ["https://explorer.harmony.one"],
              chainName: "Harmony Mainnet",
              iconUrls: ["https://harmonynews.one/wp-content/uploads/2019/11/slfdjs.png"],
              nativeCurrency: AddChainNativeCurrency(
                    name: "ONE",
                    symbol: "ONE",
                    decimals: 18)
             ))

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

let watchAsset = 
      Action(jsonRpc: .wallet_watchAsset(
             type: "ERC20",
             options: WatchAssetOptions(
                    address: "0xcf664087a5bb0237a0bad6742852ec6c8d69a27a",
                    symbol: "WONE",
                    decimals: 18,
                    image: "https://s2.coinmarketcap.com/static/img/coins/64x64/11696.png")
             ))

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

let nativeCurrency =
      AddChainNativeCurrency(name: "ONE", symbol: "ONE", decimals: 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

let watchAssetOptions = WatchAssetOptions(
      address: "0xcf664087a5bb0237a0bad6742852ec6c8d69a27a",
      symbol: "WONE",
      decimals: 18,
      image: "https://s2.coinmarketcap.com/static/img/coins/64x64/11696.png")