Create an Ethereum Transaction and pass the raw transaction data using the GraphQL endpoint

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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

1
2
3
4
5
6
7
{
"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.