How to get Transactions of a wallet using Moralis

By akohad Dec8,2022

[ad_1]

  1. Create a package.json file as below
npm init -y
npm i moralis @moralisweb3/evm-utils
{
"name": "moralis-transactions",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@moralisweb3/evm-utils": "^2.7.4",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"moralis": "^2.7.4"
}
}
API_KEY = “Your Moralis API Key”
require('dotenv').config();
const express = require('express');

const app = express();

app.use(express.json());

app.listen(8080, async () => {
console.log('server started');
});

require('dotenv').config();
const express = require('express');
const Moralis = require('moralis').default;

const app = express();
const { API_KEY } = process.env;

app.use(express.json())

async function startMoralis() {
try{
await Moralis.start({
apiKey: API_KEY,
});
}catch(err) {
console.log(err);
}
}

app.listen(8080, async () => {
startMoralis();
console.log('server started');
})

require('dotenv').config();
const express = require('express');
const Moralis = require('moralis').default;
const { EvmChain } = require('@moralisweb3/evm-utils');

const app = express();
const { API_KEY } = process.env;

app.use(express.json())

async function startMoralis() {
try{
await Moralis.start({
apiKey: API_KEY,
});
}catch(err) {
console.log(err);
}
}

app.get('/transactions', async (req, res) => {
const chain = EvmChain.ETHEREUM;
const { address } = req.body;
try{
const response = await Moralis.EvmApi.transaction.getWalletTransactions({
address,
chain,
});
res.status(200).send(response.toJSON());
}catch(err) {
console.log(err);
}
})

app.listen(8080, async () => {
startMoralis();
console.log('server started');
})

[ad_2]

Source link

By akohad

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *