diff --git a/package-lock.json b/package-lock.json index b09fe6e..101b1d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,9 @@ }, "devDependencies": { "esbuild": "^0.14.43" + }, + "engines": { + "node": "16" } }, "node_modules/@types/eventsource": { @@ -81,7 +84,15 @@ "node": "*" } }, - "node_modules/buffer": { + "node_modules/crc": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/crc/-/crc-3.8.0.tgz", + "integrity": "sha512-iX3mfgcTMIq3ZKLIsVFAbv7+Mc10kxabAGQb8HvjA1o3T1PIYprbakQ65d3I+2HGHt6nSKkM9PYjgoJO2KcFBQ==", + "dependencies": { + "buffer": "^5.1.0" + } + }, + "node_modules/crc/node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", @@ -104,14 +115,6 @@ "ieee754": "^1.1.13" } }, - "node_modules/crc": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/crc/-/crc-3.8.0.tgz", - "integrity": "sha512-iX3mfgcTMIq3ZKLIsVFAbv7+Mc10kxabAGQb8HvjA1o3T1PIYprbakQ65d3I+2HGHt6nSKkM9PYjgoJO2KcFBQ==", - "dependencies": { - "buffer": "^5.1.0" - } - }, "node_modules/detect-node": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz", @@ -726,21 +729,23 @@ "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-4.1.0.tgz", "integrity": "sha512-eJzYkFYy9L4JzXsbymsFn3p54D+llV27oTQ+ziJG7WFRheJcNZilgVXMG0LoZtlQSKBsJdWtLFqOD0u+U0jZKA==" }, - "buffer": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "requires": { - "base64-js": "^1.3.1", - "ieee754": "^1.1.13" - } - }, "crc": { "version": "3.8.0", "resolved": "https://registry.npmjs.org/crc/-/crc-3.8.0.tgz", "integrity": "sha512-iX3mfgcTMIq3ZKLIsVFAbv7+Mc10kxabAGQb8HvjA1o3T1PIYprbakQ65d3I+2HGHt6nSKkM9PYjgoJO2KcFBQ==", "requires": { "buffer": "^5.1.0" + }, + "dependencies": { + "buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + } } }, "detect-node": { diff --git a/package.json b/package.json index bdee9c7..84f695d 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,19 @@ "version": "1.0.0", "description": "", "main": "index.js", - "type": "module", + "type": "commonjs", + "engines": { + "node": "16" + }, + "targets": { + "default": { + "context": "node", + "includeNodeModules": true + } + }, "scripts": { - "build": "esbuild src/index.js --platform=node --bundle --outfile=dist/index.js", - "watch": "esbuild src/index.js --platform=node --watch", + "build": "esbuild src/index.js --platform=node --bundle --target=esnext --outfile=dist/index.js", + "watch": "esbuild src/index.js --platform=node --watch --target=esnext", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { diff --git a/src/index.js b/src/index.js index 379eeac..bfe8ffc 100644 --- a/src/index.js +++ b/src/index.js @@ -1,26 +1,30 @@ import { Asset, Keypair, Operation, Server, TransactionBuilder } from "stellar-sdk"; -const server = new Server("https://horizon-testnet.stellar.org"); +async function init() { + const server = new Server("https://horizon-testnet.stellar.org"); -const fee = await server.fetchBaseFee(); + const fee = await server.fetchBaseFee(); -const tx = new TransactionBuilder(await server.loadAccount("GC2FYDXGZKVYJXTJ7U2EK4YI6YKVCSHFZQHL24VM5K7V2S3F62FKAJPS"), { - fee: fee.toString(), - networkPassphrase: 'Test SDF Network ; September 2015' -}).addOperation(Operation.payment({ - amount: "1", - asset: Asset.native(), - destination: "GC2FYDXGZKVYJXTJ7U2EK4YI6YKVCSHFZQHL24VM5K7V2S3F62FKAJPS", -})) - .setTimeout(30) - .build(); + const tx = new TransactionBuilder(await server.loadAccount("GC2FYDXGZKVYJXTJ7U2EK4YI6YKVCSHFZQHL24VM5K7V2S3F62FKAJPS"), { + fee: fee.toString(), + networkPassphrase: 'Test SDF Network ; September 2015' + }).addOperation(Operation.payment({ + amount: "1", + asset: Asset.native(), + destination: "GC2FYDXGZKVYJXTJ7U2EK4YI6YKVCSHFZQHL24VM5K7V2S3F62FKAJPS", + })) + .setTimeout(30) + .build(); -const keyPair = Keypair.fromSecret("SBFOJVJHCKYKICNRCM5E65LTL7AAFJEERSRV6ZC3MMZUOCW2JWEFAA7E"); -tx.sign(keyPair); + const keyPair = Keypair.fromSecret("SBFOJVJHCKYKICNRCM5E65LTL7AAFJEERSRV6ZC3MMZUOCW2JWEFAA7E"); + tx.sign(keyPair); -try { - const response = await server.submitTransaction(tx); - console.log(response.id); -} catch (e) { - console.error(e); + try { + const response = await server.submitTransaction(tx); + console.log(response.id); + } catch (e) { + console.error(e); + } } + +init().then(console.log); \ No newline at end of file