Skip to content

Commit d087f67

Browse files
committed
feat(n8n): reward a beneficiary from NFT metadata
1 parent 87dc1e2 commit d087f67

File tree

1 file changed

+35
-74
lines changed

1 file changed

+35
-74
lines changed

n8n/workflows.json

Lines changed: 35 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -23030,17 +23030,6 @@
2303023030
]
2303123031
]
2303223032
},
23033-
"ExtractBeneficiaryId": {
23034-
"main": [
23035-
[
23036-
{
23037-
"index": 0,
23038-
"node": "GetTodayTransfers",
23039-
"type": "main"
23040-
}
23041-
]
23042-
]
23043-
},
2304423033
"Get Capability": {
2304523034
"main": [
2304623035
[
@@ -23052,17 +23041,6 @@
2305223041
]
2305323042
]
2305423043
},
23055-
"Get NFT": {
23056-
"main": [
23057-
[
23058-
{
23059-
"index": 0,
23060-
"node": "ExtractBeneficiaryId",
23061-
"type": "main"
23062-
}
23063-
]
23064-
]
23065-
},
2306623044
"GetCaller1": {
2306723045
"main": [
2306823046
[
@@ -23235,7 +23213,7 @@
2323523213
[
2323623214
{
2323723215
"index": 0,
23238-
"node": "Get NFT",
23216+
"node": "GetTodayTransfers",
2323923217
"type": "main"
2324023218
}
2324123219
],
@@ -23424,7 +23402,7 @@
2342423402
[
2342523403
{
2342623404
"index": 0,
23427-
"node": "Get NFT",
23405+
"node": "GetTodayTransfers",
2342823406
"type": "main"
2342923407
}
2343023408
]
@@ -23705,12 +23683,12 @@
2370523683
"parameters": {
2370623684
"operation": "executeQuery",
2370723685
"options": {
23708-
"queryReplacement": "={{ $json.agent_beneficiary_account_id }}"
23686+
"queryReplacement": "={{ $json.beneficiary_account_id }}"
2370923687
},
2371023688
"query": "select string_agg(amount, ',') as amounts\nfrom \"default\".reward_history\nwhere recipient_account_id = $1 and created_at >= now()::date"
2371123689
},
2371223690
"position": [
23713-
1680,
23691+
1280,
2371423692
-60
2371523693
],
2371623694
"type": "n8n-nodes-base.postgres",
@@ -23724,7 +23702,7 @@
2372423702
"mode": "runOnceForEachItem"
2372523703
},
2372623704
"position": [
23727-
1860,
23705+
1580,
2372823706
-60
2372923707
],
2373023708
"type": "n8n-nodes-base.code",
@@ -23737,7 +23715,7 @@
2373723715
"jsCode": "const rewardsPerDay = BigInt($('SumBigInts').first().json.total)\nconst maxRewardsPerDay = BigInt($('GetVariables').first().json.max_usage_reward_amount)\n\nreturn [{\n json: {\n shouldBeRewarded: rewardsPerDay < maxRewardsPerDay\n }\n}]"
2373823716
},
2373923717
"position": [
23740-
2040,
23718+
1900,
2374123719
-60
2374223720
],
2374323721
"type": "n8n-nodes-base.code",
@@ -23765,7 +23743,7 @@
2376523743
"parameters": {
2376623744
"amount": "={{ $('GetVariables').item.json.usage_reward_amount }}",
2376723745
"privateKey": "={{ $('GetVariables').item.json.reward_account_private_key }}",
23768-
"recipientId": "={{ $('ExtractBeneficiaryId').item.json.agent_beneficiary_account_id }}",
23746+
"recipientId": "={{ $('IsNftIssued?').item.json.beneficiary_account_id }}",
2376923747
"senderId": "={{ $('GetVariables').item.json.reward_account_id }}"
2377023748
},
2377123749
"position": [
@@ -23790,7 +23768,7 @@
2379023768
"message_thread_id": "={{ $('GetVariables').item.json.telegram_monitoring_topic_id }}"
2379123769
},
2379223770
"chatId": "={{ $('GetVariables').item.json.telegram_monitoring_chat_id }}",
23793-
"text": "=Agent beneficiary {{ $json.recipient_account_id }} rewarded for agent usage\nTx: https://nearblocks.io/txns/{{ $('Transfer NEAR').item.json.result.transaction_outcome.id }}\nCaller: @{{ $('Loop Over Items').item.json.caller_username }}\nRequest: {{ $('Loop Over Items').item.json.execution_input }}"
23771+
"text": "=Agent beneficiary {{ $('IsNftIssued?').item.json.beneficiary_account_id }} rewarded for agent usage\nTx: https://nearblocks.io/txns/{{ $('Transfer NEAR').item.json.result.transaction_outcome.id }}\nCaller: @{{ $('Loop Over Items').item.json.caller_username }}\nRequest: {{ $('Loop Over Items').item.json.execution_input }}"
2379423772
},
2379523773
"position": [
2379623774
3000,
@@ -23815,7 +23793,7 @@
2381523793
"message_thread_id": "={{ $('GetVariables').item.json.telegram_monitoring_topic_id }}"
2381623794
},
2381723795
"chatId": "={{ $('GetVariables').item.json.telegram_monitoring_chat_id }}",
23818-
"text": "=Cannot reward {{ $json.recipient_account_id }} for agent usage\nCaller: @{{ $('Loop Over Items').item.json.caller_username }}\nRequest: {{ $('Loop Over Items').item.json.execution_input }}"
23796+
"text": "=Cannot reward {{ $('IsNftIssued?').item.json.beneficiary_account_id }} for agent usage\nCaller: @{{ $('Loop Over Items').item.json.caller_username }}\nRequest: {{ $('Loop Over Items').item.json.execution_input }}"
2381923797
},
2382023798
"position": [
2382123799
2720,
@@ -23854,7 +23832,7 @@
2385423832
}
2385523833
},
2385623834
"position": [
23857-
2240,
23835+
2200,
2385823836
-60
2385923837
],
2386023838
"type": "n8n-nodes-base.if",
@@ -23948,7 +23926,7 @@
2394823926
],
2394923927
"value": {
2395023928
"amount": "={{ $('GetVariables').item.json.usage_reward_amount }}",
23951-
"recipient_account_id": "={{ $('ExtractBeneficiaryId').item.json.agent_beneficiary_account_id }}",
23929+
"recipient_account_id": "={{ $('IsNftIssued?').item.json.beneficiary_account_id }}",
2395223930
"related_item_id": "={{ $('Loop Over Items').item.json.id }}",
2395323931
"related_item_type": "usage-owner",
2395423932
"tx_hash": "={{ $json.result.transaction_outcome.id }}"
@@ -25545,9 +25523,31 @@
2554525523
"removed": false,
2554625524
"required": false,
2554725525
"type": "string"
25526+
},
25527+
{
25528+
"canBeUsedToMatch": true,
25529+
"defaultMatch": false,
25530+
"display": true,
25531+
"displayName": "beneficiary_account_id",
25532+
"id": "beneficiary_account_id",
25533+
"removed": false,
25534+
"required": false,
25535+
"type": "string"
25536+
},
25537+
{
25538+
"canBeUsedToMatch": true,
25539+
"defaultMatch": false,
25540+
"display": true,
25541+
"displayName": "beneficiary_network",
25542+
"id": "beneficiary_network",
25543+
"removed": false,
25544+
"required": false,
25545+
"type": "string"
2554825546
}
2554925547
],
2555025548
"value": {
25549+
"beneficiary_account_id": "={{$('GetCapability').item.json.name.split('/')[0]}}",
25550+
"beneficiary_network": "near",
2555125551
"id": "={{ $('Loop Over Items').item.json.capability_id }}",
2555225552
"token_id": "={{ $('SetTokenId').item.json.token_id }}"
2555325553
}
@@ -25593,21 +25593,6 @@
2559325593
"type": "@dapplets/n8n-nodes-near-protocol.writeContractCall",
2559425594
"typeVersion": 1
2559525595
},
25596-
{
25597-
"id": "e016402c-195f-4c9d-997b-a14253a65724",
25598-
"name": "Get NFT",
25599-
"parameters": {
25600-
"contractId": "={{ $('GetVariables').item.json.nft_contract_id }}",
25601-
"methodArgs": "={{ JSON.stringify({ \n token_id: $json.token_id\n}) }}",
25602-
"methodName": "nft_token"
25603-
},
25604-
"position": [
25605-
1280,
25606-
-60
25607-
],
25608-
"type": "@dapplets/n8n-nodes-near-protocol.viewContractCall",
25609-
"typeVersion": 1
25610-
},
2561125596
{
2561225597
"id": "d8399d46-273a-4725-9234-5546944a1869",
2561325598
"name": "SetTokenId",
@@ -25632,30 +25617,6 @@
2563225617
"type": "n8n-nodes-base.set",
2563325618
"typeVersion": 3.4
2563425619
},
25635-
{
25636-
"id": "d609e9f5-8653-41d0-a6b1-4ee34f975379",
25637-
"name": "ExtractBeneficiaryId",
25638-
"parameters": {
25639-
"assignments": {
25640-
"assignments": [
25641-
{
25642-
"id": "63dd2cde-dbda-4a0f-8741-c7b5b6063f46",
25643-
"name": "agent_beneficiary_account_id",
25644-
"type": "string",
25645-
"value": "={{ JSON.parse($json.result.metadata.extra).beneficiary_account_id }}"
25646-
}
25647-
]
25648-
},
25649-
"options": {
25650-
}
25651-
},
25652-
"position": [
25653-
1480,
25654-
-60
25655-
],
25656-
"type": "n8n-nodes-base.set",
25657-
"typeVersion": 3.4
25658-
},
2565925620
{
2566025621
"credentials": {
2566125622
"telegramApi": {
@@ -25829,8 +25790,8 @@
2582925790
"tags": [
2583025791
],
2583125792
"triggerCount": 1,
25832-
"updatedAt": "2025-06-02T16:39:01.000Z",
25833-
"versionId": "de216523-c5aa-4633-9abb-1103c27520e7"
25793+
"updatedAt": "2025-06-03T10:46:07.000Z",
25794+
"versionId": "be399525-e8ef-4574-98b5-f55a5de9a621"
2583425795
},
2583525796
{
2583625797
"active": false,

0 commit comments

Comments
 (0)