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:

Examples

Create a TransactionsTrigger

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: [
        "matteo@atomic.eu.com"
        ]
      }
    }
    ]
  }) {
    UUID
  }
}

Create an EventsTrigger

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: [
            "matteo@atomic.eu.com"
          ]
        }
      }
    ]
  }) {
    UUID
  }
}

Create a ContractsTrigger

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: [
            "matteo@atomic.eu.com"
          ]
        }
      }
    ]
  }) {
    UUID
  }
}

Last updated