# Create transactions to an EVM compatible chain that TrustVault does not support natively

Who is this tutorial for:

• API users that want to interact to an EVM compatible chain that TrustVault does not support natively
• API users that want to send native currency transactions to an EVM compatible chain that TrustVault does not support natively
• API users that want to invoke smart contract methods (including ERC-20 transfers) to an EVM compatible chain that TrustVault does not support natively

## Brief Outline

Supported EVM Compatible Chains

Support Chains has the benefit of:

• The balance and transactions of an addresses in the chain can be viewed in the iOS TrustVault app and TrustVault Web
• The ability to construct a transaction for the chain in the iOS TrustVault app and TrustVault Web
• The API supports creating a transaction for a supported asset in the chain by passing just the assetSymbol (e.g. LINK)
• Webhook users can get a webhook when ERC-20s are received in the chain with full ERC-20 data payload including a valuation

Unsupported EVM Compatible Chains

All EVM compatible chains are unsupported by default which means:

• They can only be interacted via TrustVault API or MetaMask x TrustVault chrome extension

In order to interact via TrustVault API with an EVM compatible chain that TrustVault does not support natively there are a few steps that needs to be done manually (these are done automatically for natively supported chains). The steps are:

1. Decide the EVM compatible chain you want to interact with and get the chain information
1. see EVM chain info (RPC URL and Chain ID) section
2. Decide if you are sending a native currency (i.e. MATIC on Polygon) or invoking a smart contract (including ERC-20 transfers) and follow the correct instructions:
3. Construct the raw transaction by calculating the transaction details
4. Submit the raw transaction to TrustVault setting the sendToNetworkWhenSigned: false (the signed transaction must be sent to network manually)
5. Workflow / Sign the transaction as normal using your iOS device
6. Poll the transaction request for the correct state
7. Grab the rawTransactionBytes and submit to network

## Sending native currency transaction (EVM compatible chain)

To send a native currency transaction to an EVM compatible chain that TrustVault does not support natively:

1. Create a transaction using the steps in Native Currency Transaction Mutation
1. Take note of the requestId from the response (required for step 2 and 3)
2. Add signatures using the TrustVault IOS app or Add Signature Mutation (requestId required) for externally held device keys.
3. Poll for the rawTransactionBytes using the steps in Get rawTransactionBytes of the transaction request
4. Broadcast the rawTransactionBytes to the EVM compatible chain using the steps in Broadcast the rawTransactionBytes

## Invoking a smart contract method (EVM compatible chain)

When sending a smart contract transaction we can invoke any method available in the ABI of a smart contract. For transferring ERC-20 use the transfer method of the ERC-20 smart contract.

See the steps in Generate data field on how to select the available methods of a smart contract.

To invoke a smart contract method in an EVM compatible chain that TrustVault does not support natively:

1. Create a transaction using the steps in Smart contract transaction mutation
1. Take note of the requestId from the response (required for step 2 and 3)
2. Add signatures using the TrustVault IOS app or Add Signature Mutation (requestId required) for externally held device keys.
3. Poll for the rawTransactionBytes using the steps in Get rawTransactionBytes of the transaction request
4. Broadcast the rawTransactionBytes to the EVM compatible chain using the steps in Broadcast the rawTransactionBytes

## Native Currency Transaction Mutation

The following fields are needed in order to send a native currency transaction to an EVM compatible chain that TrustVault does not support natively:

Request:

Variables:

Response:

## Smart contract transaction mutation

The following fields are needed in order to invoke a method of a smart contract in an EVM compatible chain that TrustVault does not support natively:

Request:

Variables:

Response:

## EVM chain info (RPC URL and Chain ID)

RPC URL - this value is needed to get necessary information from the EVM compatible chain.
Chain ID - chain identifier where this transaction is going to be sent to

Please refer to rpc.info for the RPC URL and Chain ID of a particular EVM compatible chain

## Get value

The value of the native currency (i.e. MATIC on Polygon) sent with this transaction (integer string in wei units)

Use this ethereum unit converter to convert the Ether value (i.e native currency) to wei units.

## Get gasPrice

The price per unit of gas in wei units (integer string). The eth_gasPrice JSON RPC method will be used to grab the gasLimit for the transaction.

Request:

CHAIN_RPC_URL - EVM chain info (RPC URL and Chain ID)

Response:

convert the hex result "0x70295f4f0" to integer string

## Get gasLimit

The maximum units of gas the transaction is allowed to use (integer string). The eth_estimateGas JSON RPC method will be used to grab the gasLimit for the transaction.

Request:

CHAIN_RPC_URL - EVM chain info (RPC URL and Chain ID)
TRANSACTION_TO_FIELD - for native currency transactions this is the recipient address, for smart contract invocations (including ERC-20 transfers) this is the smart contract address

Response:

convert the hex result "0x5208" to integer string

## Get nonce

The number of transactions made by the sender prior to this one (integer). The eth_getTransactionCount JSON RPC method will be used to grab the current nonce value.

Request:

CHAIN_RPC_URL - EVM chain info (RPC URL and Chain ID)
TRANSACTION_FROM_FIELD - the Ethereum TrustVault address where the transaction will come from

Response:

convert the result to an integer

## Generate data field

The data field is optional and only required if you want to invoke methods of a smart contract (this includes ERC-20 transfers).

Follow this guide to get the ABI of the smart contract you want to invoke. Please check the ABI of the method you want to invoke and the parameters it accepts.

The example below calls the transfer method which takes in 2 arguments:

• address - type address
• value - type uint256

This is an example ABI of the WETH contract in Polygon: WETH ABI

## Get rawTransactionBytes of the transaction request

The rawTransactionBytes will be only be populated once the transaction request have enough signature to satisfy the wallet policy, otherwise it will be null.

Request:

Variables:

REQUEST_ID - the requestId of the transaction request from either Native Currency Transaction Mutation or Smart contract transaction mutation response

Response:

Once the transaction request has collected enough signatures to satisfy the policy the rawTransactionBytes will be populated and can now be broadcasted to the EVM compatible network.
The eth_sendRawTransaction JSON RPC method will used to broadcast the rawTransactionBytes.
The response.result is the transactionHash which you can query on the EVM compatible chain blockchain explorer.