Who is this tutorial for:

  • API users that will be using GraphQL directly
  • API users that want to send Ethereum "Raw" Transactions for more complex transaction calls

Brief Outline

The TrustAPI can do lots of the heavy lifting when creating an Ethereum transaction such as calculating the nonce, the gasPrice and gasLimit for your transaction. However, this only works for basic ETH or ERC-20 transactions.

In order to send more complex transactions (.e.g contract creation) but still take advantage of TrustVaults features such as multi-sig signing, you may will need to change the way you construct the transaction.

GraphQL

The following GraphQL mutation will allow you to construct a "raw" transaction. This is lower level transaction and will require you to specify the exact payload of the transaction. In the example below the transaction data is:

0xa9059cbb000000000000000000000000a346b347217d10b6a5925f870aa14e7695e4eabe000000000000000000000000000000000000000000000000000000001dcd6500

This is actually a transaction to send an ERC20 transfer. In order to create this payload you will need to use a 3rd party library or construct the data yourself.

For this mutation to work you MUST:

  • set the assetSymbol to ETH . If you set the value to anything else it will fail
  • set the fromAddress to an address you own and can sign transactions for
  • set the to address as the contract you want to call. NB: Don't confuse this field when using this mutation to send a basic ERC-20 transfer, as the to address is the recipient of the tokens.
Copy
Copied
mutation (
	$from: String!,
	$to: String!,
	$value: String!,
	$assetSymbol: String!
	$data: String
) {
	createEthereumTransaction(
		createTransactionInput: {
			ethereumTransaction: {
				assetSymbol: $assetSymbol
				fromAddress: $from
				to: $to
				value: $value
				speed: FAST
				data: $data
			}
			source: "API",
			sendToNetworkWhenSigned: true
			sendToDevicesForSigning: true
		}
	) {
		... on CreateEthereumTransactionResponse {
			requestId
		}
		signData {
			transaction {
				to
				fromAddress
				value
				gasPrice
				gasLimit
				nonce
				chainId
				data
			}
			hdWalletPath {
				hdWalletPurpose
				hdWalletCoinType
				hdWalletAccount
				hdWalletUsage
				hdWalletAddressIndex
			}
			unverifiedDigestData {
				transactionDigest
				signData
				shaSignData
			}
		}
		assetRate
		chainRate
	}
}

Variables

Copy
Copied
{
 "from": "<Your Address>",
 "to":"<Contract Address>",
 "assetSymbol": "ETH",
 "value": "0",
 "data": "0xa9059cbb000000000000000000000000a346b347217d10b6a5925f870aa14e7695e4eabe000000000000000000000000000000000000000000000000000000001dcd6500"
}

This will create a transaction that will follow the regular multi-sig rules as any of your wallets and can be signed by iOS devices, external signing keys or our co-signing service as specified in your wallet policy.