Search
⌃K

Create

How to create a new trigger via GraphQL
Create is a mutation that allows you to create triggers and returns data from the newly created trigger

Available create mutations

In HAL the following create mutations are available:
Mutations Name
Scope
createTransactionsTrigger
To create a TransactionsTrigger
createEventsTrigger
To create an EventsTrigger
createContractsTrigger
To create a ContractsTrigger
updateTriggerStatus
To update a trigger status from active to inactive or viceversa

Examples

Create a TransactionsTrigger

Query
Result
mutation {
createTransactionsTrigger(input: {
name: "Watch Transactions Example",
type: TransactionsTrigger,
statement: {
filters: [
{
condition: {
attribute: "0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208",
predicate: Eq
},
parameter: {
name: "To"
},
type: BasicFilter
},
{
method: {
name: "trade"
},
parameter: {
name: "tradeValues",
type: "uint256[8]",
index: 1
},
type: CheckFunctionParameter,
condition: {
attribute: "100",
predicate: BiggerThan
}
},
{
method: {
name: "trade"
},
parameter: {
name: "tradeAddresses",
type: "address[4]",
index: 1
},
type: CheckFunctionParameter,
condition: {
attribute: "0xB8c77482e45F1F44dE1745F52C74426C631bDD52",
predicate: Eq
}
}
],
contract: {
address: "0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208",
abi: [...]
}
},
actions: [
{
type: Email,
attributes: {
body: "BlockNumber is $BlockNumber$\nBlockHash is $BlockHash$\nTransactionHash is $TransactionHash$\nBlockTimestamp is $BlockTimestamp$\nFrom is $From$\nTo is $To$\nValue is $Value$\nGas is $Gas$\nGasPrice is $GasPrice$\nNonce is $Nonce$",
subject: "Watch Transactions Example",
to: [
]
}
}
]
}) {
UUID
}
}
{
"data": {
"createTransactionsTrigger": {
"UUID": "5b2d1664-8215-4910-9186-241a8f8385f9"
}
}
}

Create an EventsTrigger

Query
Result
mutation {
createEventsTrigger(input: {
name: "EventsTrigger Example",
type: EventsTrigger,
statement: {
contract: {
address: "0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208",
abi: [...]
},
filters: [
{
method: {
name: "Trade"
},
parameter: {
name: "amountBuy",
type: "uint256",
index: null
},
type: CheckEventParameter,
condition: {
attribute: "10000000",
predicate: BiggerThan
}
},
{
method: {
name: "Trade"
},
parameter: {
name: "amountSell",
type: "uint256",
index: null
},
type: CheckEventParameter,
condition: {
attribute: "0877482451441745527442663152",
predicate: Eq
}
}
]
},
actions: [
{
type: Email,
attributes: {
body: "BlockNumber is $BlockNumber$\nBlockHash is $BlockHash$\nTransactionHash is $TransactionHash$\nBlockTimestamp is $BlockTimestamp$\n\nEvent name is: $MethodName$",
subject: "EventsTrigger Example",
to: [
]
}
}
]
}) {
UUID
}
}
{
"data": {
"createEventsTrigger": {
"UUID": "39d3cc06-83ef-4bc2-b580-dcdc75466360"
}
}
}

Create a ContractsTrigger

Query
Result
mutation {
createContractsTrigger(input: {
name: "ContractsTrigger Example",
type: ContractsTrigger,
statement: {
contract: {
address: "0x09cabec1ead1c0ba254b09efb3ee13841712be14",
abi: [...]
},
inputs: [
{
type: "uint256",
name: "eth_bought",
value: "1"
}
],
outputFilters: [
{
parameter: {
type: "uint256",
name: "out"
},
returnIndex: 0,
condition: {
attribute: "140",
predicate: BiggerThan
}
}
],
method: {
name: "getTokenToEthOutputPrice"
}
},
actions: [
{
type: Email,
attributes: {
body: "BlockNumber is $BlockNumber$\nBlockHash is $BlockHash$\nBlockTimestamp is $BlockTimestamp$\n\nThe contract wich originated this trigger is: $ContractAddress$\n\nAll values returned by the function: $ReturnedValues$",
subject: "ContractsTrigger Example",
to: [
]
}
}
]
}) {
UUID
}
}
{
"data": {
"createContractsTrigger": {
"UUID": "8b944a2f-da6b-41a6-895b-c39fcac5011e"
}
}
}
Last modified 2yr ago