Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
import {
Coinbase, Webhook,
} from "@coinbase/coinbase-sdk";

export default {
type: "app",
app: "coinbase_developer_platform",
propDefinitions: {},
propDefinitions: {
walletAddress: {
type: "string",
label: "Address",
description: "The address of the wallet to monitor. Example: `0x8fddcc0c5c993a1968b46787919cc34577d6dc5c`",
},
networkId: {
type: "string",
label: "Network ID",
description: "The network ID of the wallet to monitor. Example: `base-mainnet`",
async options() {
const networks = Coinbase.networks;
return Object.values(networks);
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
configure() {
const apiKeyName = this.$auth.api_key_id;
const privateKey = this.$auth.secret_key;
Coinbase.configure({
apiKeyName,
privateKey,
});
},
listWebhooks() {
return Webhook.list();
},
createWebhook(opts) {
return Webhook.create(opts);
},
deleteWebhook(webhook) {
return webhook.delete();
},
},
};
};
8 changes: 6 additions & 2 deletions components/coinbase_developer_platform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/coinbase_developer_platform",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Coinbase Developer Platform Components",
"main": "coinbase_developer_platform.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@coinbase/coinbase-sdk": "^0.25.0",
"@pipedream/platform": "^3.1.0"
}
}
}
29 changes: 29 additions & 0 deletions components/coinbase_developer_platform/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import coinbase from "../../coinbase_developer_platform.app.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
props: {
coinbase,
db: "$.service.db",
http: "$.interface.http",
},
methods: {
_getWebhookId() {
return this.db.get("webhookId");
},
_setWebhookId(webhookId) {
this.db.set("webhookId", webhookId);
},
generateMeta() {
throw new ConfigurationError("generateMeta is not implemented");
},
},
async run(event) {
const { body } = event;
if (!body) {
return;
}
const meta = this.generateMeta(body);
this.$emit(body, meta);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import common from "../common/base.mjs";
import { ConfigurationError } from "@pipedream/platform";
import sampleEmit from "./test-event.mjs";

export default {
...common,
name: "New Wallet Event (Instant)",
key: "coinbase_developer_platform-new-wallet-event",
description: "Emit new event for each new wallet event. [See the documentation](https://docs.cdp.coinbase.com/webhooks/cdp-sdk#external-address-webhook)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
...common.props,
walletAddress: {
propDefinition: [
common.props.coinbase,
"walletAddress",
],
},
networkId: {
propDefinition: [
common.props.coinbase,
"networkId",
],
},
},
hooks: {
async activate() {
this.coinbase.configure();
const webhook = await this.coinbase.createWebhook({
notificationUri: this.http.endpoint,
eventType: "wallet_activity",
networkId: this.networkId,
eventTypeFilter: {
addresses: [
this.walletAddress,
],
wallet_id: "",
},
});

if (!webhook?.model?.id) {
throw new ConfigurationError("Failed to create webhook");
}

this._setWebhookId(webhook.model.id);
},
async deactivate() {
this.coinbase.configure();
const webhookId = this._getWebhookId();
if (webhookId) {
const { data: webhooks } = await this.coinbase.listWebhooks();
const webhook = webhooks.find((webhook) => webhook.model.id === webhookId);
await this.coinbase.deleteWebhook(webhook);
}
},
},
methods: {
...common.methods,
generateMeta(body) {
return {
id: body.transactionHash,
summary: `New ${body.eventType} event`,
ts: Date.parse(body.blockTime),
};
},
},
sampleEmit,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
"blockHash": "0x351bd04dfe350fca186cd47080220283a75d07018ed251748a4ad19e7f327caf",
"blockNumber": 20305354,
"blockTime": "2024-09-27T21:16:40.000Z",
"contractAddress": "0xab39a8b6801b0b6aa20e9a1953c861ec0a57d175",
"eventType": "erc20_transfer",
"from": "0x10db590ffa5b7bc46cffbd436180e01b6c5c0af6",
"logIndex": "121",
"network": "base-sepolia",
"to": "0x4a9ab171e31daff484c70921f2f5e89a8fe12f59",
"transactionHash": "0x940db3006449456b386397ab42114134d745d2876196226444601670f3e99db8",
"transactionIndex": "19",
"value": "1000000",
"webhookId": "66bd79d0b9c200eae1a43165"
}
2 changes: 1 addition & 1 deletion components/timescaledb/timescaledb.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Loading
Loading