Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,48 @@
import {
Coinbase, Wallet, Webhook,
} from "@coinbase/coinbase-sdk";

export default {
type: "app",
app: "coinbase_developer_platform",
propDefinitions: {},
propDefinitions: {
walletId: {
type: "string",
label: "Wallet ID",
description: "The ID of the wallet to use",
async options() {
this.configure();
const { data } = await this.listWallets();
return data?.map((wallet) => ({
label: `${wallet.model.network_id} - ${wallet.model.default_address.wallet_id}`,
value: wallet.model.default_address.wallet_id,
})) || [];
},
},
},
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,
});
},
getWallet(walletId) {
return Wallet.fetch(walletId);
},
listWallets() {
return Wallet.listWallets();
},
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 <[email protected]> (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,69 @@
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,
walletId: {
propDefinition: [
common.props.coinbase,
"walletId",
],
},
},
hooks: {
async activate() {
this.coinbase.configure();
const wallet = await this.coinbase.getWallet(this.walletId);
const networkId = wallet.model.network_id;
const addresses = [
wallet.model.default_address.address_id,
...wallet.addresses,
];

const webhook = await this.coinbase.createWebhook({
notificationUri: this.http.endpoint,
eventType: "wallet_activity",
networkId,
eventTypeFilter: {
addresses,
wallet_id: this.walletId,
},
});

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"
}
Loading
Loading