I need to get all transactions from aa address on bsc. I tried bscscan api but it doesn't give everything like burning minting actions, they just give transfers , how can I get all transactions with web3 js or web3 py. I would appreciate if someone can help me
You need scan all block and found that you need. This is very bad way.
Other way -- you can use API
check etherscan.io api you can get a list of all transactions easily as an alternative
https://etherscan.io/apis
http://api.etherscan.io/api?module=account&action=txlist&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken
and work with this answer.
This is easy way, but no easy way to get all transaction via web3js or web3py.
But if you need only specified events -- that was much easy.
you need function getPastEvents
const START_BLOCK = 7700000;
const END_BLOCK = 7701000;
contract.getPastEvents("allEvents",
{
fromBlock: START_BLOCK,
toBlock: END_BLOCK // You can also specify 'latest'
})
.then(events => console.log(events))
.catch((err) => console.error(err));
You can set mint or burn events only.
https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#getpastevents
Related
I’m wanting to use Metamask in my app to let users pay a fixed ETH fee (plus gas) to call a method from my Solidity contract. I looked at the Metamask documentation and the eth_sendTransaction method seems close to what I need; eth_sendTransaction would certainly allow me to request ETH from a user, but the “data” parameter is a bit confusing.
The Metamask docs say:
data is optional, but used for defining smart contract creation and interaction
and
also used for specifying contract methods and their parameters.
So “data” represents my method and its parameters, but how does Metamask (or window.ethereum, rather) know the contract whose methods I’m trying to call?
Don’t you normally have to provide a contract address and ABI/JSON in order to interact with a deployed contract? In short, is it possible to do what I’ve described with just Metamask alone? Or do you have to do other client-side setups in order to call a method with eth_sendTransaction?
Edit: by the way TylerH, the answer involved using web3.js. Maybe don't edit people's posts unless you know what the hell you're talking about. Just a thought...
Yes you will need the contract abi in order to get the information you need to include in the data that you're passing to the contract. There are also a few other things that you will need to accomplish this:
First you will need to make sure you download the ethers.js, and #alch/alchemy-web3 npm libraries into your application. Secondly you will need a provider API key from a platform like Alchemy in order to communicate with the contract abi. Lastly, you will need the contract abi which can be found at the bottom of the contract section of etherscan. There is plenty of information on how to obtain these things online, so I won't go over how to configure them here.
Once you have these, you are ready for the next step.
I suggest creating this in a utilities file somewhere in your applications file system, but the idea is this:
const alchemyKey = process.env.ALCHEMY_KEY;
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS;
const { createAlchemyWeb3 } = require("#alch/alchemy-web3");
const web3 = createAlchemyWeb3(alchemyKey);
const contractABI = require('../contract-abi.json');
export const contract = new web3.eth.Contract(contractABI, CONTRACT_ADDRESS);
export const yourMethod = () => {
if(window.ethereum.request({method: 'eth_requestAccounts'})){
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const address = await signer.getAddress();
const tx = {
from: address,
to: CONTRACT_ADDRESS,
value: "some wei value", // this is the value in wei to send
data: contract.methods.YOUR_CONTRACT_METHOD_HERE().encodeABI()
}
const txHash = await window.ethereum.request({
method: 'eth_sendTransaction',
params: [tx]
});
// do something with your transaction hash here
console.log({txHash});
}else{
console.log('user must connect wallet');
}
}
So the value that is populated in the data field of our transaction comes from calling the method that we are trying to invoke in our contract. This is encoded, and then we pass this information along with the rest of our transaction data.
This is a very short and brief description as to what this does, and I hope this is what you're looking for. If you need any more help I'm always available to chat on Twitter #_syndk8.
I am trying to create an NFT using web3.js and spl-token.js.
However, i need to add meta data (like the name of the token or other attributes), otherwise it just shows up as "Unknown Token" in my wallet.
This is the relevant part of the code where I am minting the token:
let mint = await splToken.Token.createMint(
connection,
fromWallet,
fromWallet.publicKey,
null,
0,
splToken.TOKEN_PROGRAM_ID
);
Otherwise the code is similar to the answers on this question: I would like to mint a new token on solana. How can I do this using solana-web3.js?
There does not seem to be any documentation whatsoever, except for the structure of the meta data (which I found here: https://docs.phantom.app/integrating/tokens/on-chain-metadata).
If anyone could point me in the right direction with an example or documentation it would be really much appreciated. Thank you!
In order to add metadata to NFT you need to invoke this program spl_token_metadata::instruction::create_metadata_accounts. You can find the documentation here.
PS: The example above is in Rust. To do it in JavaScript is like that:
import { Metaplex, keypairIdentity } from "#metaplex-foundation/js";
const metaplex = new Metaplex(connection);
metaplex.use(keypairIdentity(keypair));
const mintNFTResponse = await metaplex.nfts().create({
uri: "https://ffaaqinzhkt4ukhbohixfliubnvpjgyedi3f2iccrq4efh3s.arweave.net/KUAIIbk6p8oo4XHRcq0U__C2r0mwQaNl0gQow4Qp9yk",
maxSupply: 1,
});
Like described here is another exemple.
Create a metadata for an NFT token in Solana is quite complicated. It is because in Solana SPL-token account would not carry the Metadata. Instead, you have to create another account to carry such data. So, I suggest you to use Metaplex's Candy Machine to make your own NFT with Metadata. You may get more information from their github:
https://github.com/metaplex-foundation/metaplex/
I am using the etherscan-api here: (https://sebs.github.io/etherscan-api/#txlist) to get the list of transactions for a user (given public key), and I am getting the list of cleared transactions only, even though on etherscan.io I can see all pending transactions as well, so the information is "there". Digging into the source https://github.com/sebs/etherscan-api/blob/master/lib/account.js#L122, I find no indication of where I can look to find pending transactions. Code below:
const etherscan = require('etherscan-api').init(ETHERSCAN_TOKEN, 'ropsten', '3000');
etherscan.account
.txlist(public_key, 1, 'latest', 1, 100, 'asc')
.then(res => {
console.log("tx_list: ", res.result)
})
// get num of transactions
etherscan.proxy
.eth_getTransactionCount(public_key, 'latest')
.then(res => {
let count = res.result
console.log("eth_getTransactionCount: ", parseInt(count))
})
Etherscan doesn't provide pending transactions in their API.
It's probably because of the nature of how pending transactions are collected and displayed. All pending transactions are collected together in the Ethereum mempool. My guess is that Etherscan adds each entry from mempool to some kind of quickly searchable database such as ElasticSearch, and removes the DB entry when the transaction is taken off the mempool. The address detail page then performs a simple search in ES, filtering only transactions from/to this particular address.
If your web3 provider allows websocket connections and subscriptions, you can subscribe to the pendingTransactions event.
It fires an event everytime a new transaction is added to the mempool. The event contains only the transaction hash (and no additional data such as the sender and receiver).
Because the event contains only tx hash, it's not very effecient to always perform a new query on the tx details, but it's useful in some other cases such as when you know the tx hash beforehand and you only want to know when it has been successfully broadcasted.
There's also BlockCypher REST API that has a limited free plan (and somewhat less limited paid plans) that returns all pending transactions including the tx details so that you can perform your own search on the result. See their docs if this fits your use case.
So I wanted to implement report&ban system and I decided to use an embedded message with reactions added to it. Moderator can either agree or disagree. For example once 10 moderators agree with the complaint the user mentioned in this message should be banned or kicked.
I thought of using client.on('messageReactionAdd', (messageReaction, user) => {}), but it only checks cached messages. Then I found discordjs.guide about reactions and they showed how to use client.on('raw', (event) => {}), but it's was abandoned long time ago and I didn't even found any mentions about this official Discord.js documentation. Message has .awaitReactions(filter, [options]), but I have to mark voting messages somehow and then searching them in a some kind client of method which is super complicated.
Here's what I have:
const service = client.channels.get('id');
let user = msg.mentions.users.first();
if (!user) {
msg.reply('Couldn\'t find the user!')
return 1;
}
args.shift();
let reason = args.join(' ').trim();
if (!reason) {
msg.reply('No reason to create a complaint!')
return 1;
}
msg.channel.send(`I've created and sent a user complaint about ${user.tag}!)`)
.catch((e) => console.log(e));
msg.delete();
const emb = new Discord.RichEmbed()
.setTitle('User complaint')
.addField('Who?', `**User: ${user.tag}**`)
.addField('Reason?', `**Reson: ${reason}**`)
.setColor('#ff7b00')
.setFooter('Please take action');
service.send(emb)
.then(async msg => {
await msg.react('✅')
msg.react('❌')
})
.catch(e => {
console.error()
msg.reply('Couldn\'t send a user complaint!');
return 1;
})
Is it even possible? I explained my previous plan earlier, but is there a way to make is simpler?
1. Database
You should use either message.awaitReactions(); or client.on('messageReactionAdd', ...); and fetch the message on the bot ready event.
It's a very simple process. You'd require a database to store the message ID's, channel ID and of course, server ID. After that make a small algorithm inyour ready event to go through all the messages collected from the database and use either message.awaitReactions(); or client.on('messageReactionAdd', ...); on them.
I'd suggest using message.awaitReactions(); if you decide to go with the database method.
2. Global Array (Less Recommended)
If you have a really simple bot and you can't use a database then I'd recommend having a global array storing all the message IDs and using those for the client.on('messageReactionAdd', ...); event.
You'd have to check if the ID from the message array matches the ID of the message collected in the event and then act accordingly.
This method would work well for the smaller bots, but if you have a bigger, multi-server bot, then I'd highly recommend going with the database version because this version would not work after the bot restarts.
I was hoping to write the authentication step myself instead of clone the samples repository so I can get a better understanding. Trying to keep it simple, I changed the onTurn function to:
public onTurn = async (context: TurnContext) => {
if (context.activity.type === ActivityTypes.Message) {
await context.sendActivity(CardFactory.oauthCard( ... );
}
};
But when I test it in the bot emulator, no oauth card shows up, nor any other response. But when I test the bot-authentication-msgraph sample in GitHub, it works fine. Can't I just use the one-line of code to authenticate users: context.sendActivity(CardFactory.oauthCard( ... )?
CardFactory.oauthCard will build a card as an attachment, but you still have to add it to an activity to send it out. This should do what you're looking for:
await context.sendActivity(MessageFactory.attachment(CardFactory.oauthCard(...)));