# Pushed, contract and other sources

> Push events from your own service with a key, decode any contract's events, write a source in TypeScript, or run one on a machine of your own.

## Pushed sources

Run a bot, a webhook or a stream reader anywhere and push its events to ftw.trade.

```steps
### Create the source
Name it and declare its fields (Sources → New, or `create_source`). You get a key starting `fws_`, shown once.
### Post events
Each event is a JSON object with those fields.
### Use it
Strategies, workflows and scripts read and trigger on it like any other source.
```

```sh
curl -X POST https://ftw.trade/api/sources/kol-calls/events \
  -H "Authorization: Bearer fws_…" \
  -H "content-type: application/json" \
  -d '{"token":"0x…","caller":"alice","confidence":0.8}'
```

Events are checked against the fields you declared, and a source can have **cases** (a sum type): each event one of several shapes, read with `match`. Replace a leaked key at any time.

For high-rate feeds there is a durable path from your own NATS JetStream stream, with exactly-once commits: see `create_source_ingress` in the MCP tools.

## Contract-event sources

Any event any contract emits, on any EVM chain you've added: give the chain, the contract's address and the event's signature. ftw.trade filters at the RPC by the indexed values, rechecks for logs the RPC left out, and decodes each into fields. For a filter or a transform on top, use a [Flowscript source](https://docs.ftw.trade/sources/flowscript-sources) with an `event` input.

## TypeScript sources

A script that polls an API every second or more, or listens to ftw.trade's streams or a websocket, and publishes typed events:

```ts
import { source, t } from '@ftw/sdk';

export default source({
  name: 'eth-gas',
  fields: { gwei: t.number() },
  every: '1m',
  policy: { egress: ['api.example.com'] },
  async poll(ctx) {
    const r = await ctx.fetch('https://api.example.com/gas');
    return { gwei: (r.json as { fast: number }).fast };
  },
});
```

It runs in ftw.trade's sandbox and can reach only the hosts its policy names. See [TypeScript scripts](https://docs.ftw.trade/automate/scripts).

## Machine sources

When a source needs npm packages, a long-lived socket or real compute, run it on a machine of your own: ftw.trade starts and keeps a small machine for your account and runs your code there. It's paid from your credits (from $5 a month for the smallest size), and only accounts that save one get one. See [Credits and limits](https://docs.ftw.trade/account/credits-and-limits).

## Timers

Every period from a minute to a week is a source too (`every-1h`), made the first time a workflow uses it, so repeating jobs are workflows triggered by a timer.
