UNPKG

n8n-nodes-wax

Version:

n8n Community Node Package for the WAX Blockchain

125 lines 4.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WaxTransferToken = void 0; const util_1 = require("util"); const eosjs_1 = require("eosjs"); const eosjs_jssig_1 = require("eosjs/dist/eosjs-jssig"); class WaxTransferToken { constructor() { this.description = { hidden: true, displayName: 'WAX Transfer Token', name: 'waxTransferToken', icon: 'file:wax.svg', group: ['transform'], version: 1, description: 'Transfer tokens on the WAX blockchain', defaults: { name: 'Transfer Token', }, credentials: [ { name: 'waxPrivateKeyApi', required: true, } ], inputs: ['main'], outputs: ['main'], properties: [ { displayName: 'To Account', name: 'to', type: 'string', default: '', required: true, }, { displayName: 'Amount', name: 'amount', type: 'number', default: 1, required: true, description: 'Amount of tokens to transfer (e.g., 1)', }, { displayName: 'Symbol', name: 'symbol', type: 'string', default: 'WAX', required: true, description: 'Token symbol (e.g., "WAX")', }, { displayName: 'Precision', name: 'precision', type: 'number', default: 8, description: 'Number of decimal places for the token (default is 8)', }, { displayName: 'Memo', name: 'memo', type: 'string', default: '', }, { displayName: 'API Endpoint', name: 'endpoint', type: 'string', default: 'https://wax.greymass.com', required: true, }, { displayName: 'Contract', name: 'contract', type: 'string', default: 'eosio.token', required: true, description: 'Token contract (e.g., "eosio.token" for WAX)', } ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { const credentials = await this.getCredentials('waxPrivateKeyApi'); const from = credentials.account; const key = credentials.privateKey; const to = this.getNodeParameter('to', i); const amount = this.getNodeParameter('amount', i); const symbol = this.getNodeParameter('symbol', i); const precision = this.getNodeParameter('precision', i) || 8; const memo = this.getNodeParameter('memo', i); const endpoint = this.getNodeParameter('endpoint', i); const contract = this.getNodeParameter('contract', i); const formattedAmount = amount.toFixed(precision); const quantity = `${formattedAmount} ${symbol}`; const signatureProvider = new eosjs_jssig_1.JsSignatureProvider([key]); const rpc = new eosjs_1.JsonRpc(endpoint, { fetch }); const api = new eosjs_1.Api({ rpc, signatureProvider, textDecoder: new util_1.TextDecoder(), textEncoder: new util_1.TextEncoder() }); const actions = [{ account: contract, name: 'transfer', authorization: [{ actor: from, permission: 'active' }], data: { from, to, quantity, memo, } }]; const result = await api.transact({ actions }, { blocksBehind: 3, expireSeconds: 30, }); returnData.push({ json: { result } }); } return [returnData]; } } exports.WaxTransferToken = WaxTransferToken; //# sourceMappingURL=WaxTransferToken.node.js.map