How can I get approval llist of eth - ethereum

I can find my approval list in etherscan.io. But I don't see any api to get list of approval.
https://etherscan.io/tokenapprovalchecker?search=0xf7931b9b1fff5fc63c45577c43dfc0d0def16c46

Etherscan builds their own database of approvals aggregated from the Approval event logs emitted by transactions.
Example subscribing to event logs with web3js:
web3.eth.subscribe("logs", {
topics: [
// event signature standardized by ERC20 and ERC721
web3.utils.keccak256("Approval(address,address,uint256)")
]
}, (err, event) => {
console.log(event)
// `address` - token contract emitting the event
// `topics[0]` - approver
// `topics[1] - spender
// `topics[2]` - ERC721 token ID
// `data` - ERC20 amount
})
Docs: https://web3js.readthedocs.io/en/v1.8.1/web3-eth-subscribe.html#subscribe-logs

Related

Is there an API for ethereum address monitoring? Or how to get notifications when an address is paided

Consider the simple scenario: some address transfers 100 usdt to address A; is there a method or api to watch on address A to get automated notifications? What is the best practice for these payin notifications of many (~100+) addresses?
You can subscribe to Transfer event logs emitted by the USDT contract. As defined in the ERC-20 standard, the second param of the event log is the recipient address.
Example using web3js:
const options = {
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT contract on Ethereum
topics: [
web3.utils.keccak256("Transfer(address,address,uint256)"), // hash of the event definition
null, // any sender
["0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF"] // recipient addresses
]
};
web3.eth.subscribe("logs", options, (err, data) => {
console.log(data);
});

Ethereum smart contract returns "Fail with error 'AssetContractShared#_requireMintable: ONLY_CREATOR_ALLOWED' " on rinkeby network

I'm trying to test a smart contract function on the rinkeby test network, which migrates multiple tokens to the new contract. I.e. I want to burn ERC-721 tokens (send them to a burn address), which are stored on the Opensea contract, and then remint it on the new contract.
Everything worked fine when I tested the function on a local etherum network fork (with ganache-cli) but on the rinkeby network I get the following error:
errors.js:87 Uncaught (in promise) Error: Transaction has been reverted by the EVM:
{
"blockHash": "0x1b6f3907c56626ed6e66a090fdc5c4e14723fa4be11137227c5fcb20f89a7c8c",
"blockNumber": 9780743,
"contractAddress": null,
"cumulativeGasUsed": 823380,
"effectiveGasPrice": "0x9502f90a",
"from": "0x4e3a2cd1904ba26f9bbcd196802dceec94cf97fd",
"gasUsed": 204890,
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": false,
"to": "0x33a7bbd2f44c012ee19c0e0a9190bb6ba555ffb4",
"transactionHash": "0x8e2cbd9bc333fd56788b51e21568be02a62548468f43ac86859766655818dce1",
"transactionIndex": 6,
"type": "0x2",
"events": {}
}
at Object.TransactionError (errors.js:87)
at Object.TransactionRevertedWithoutReasonError (errors.js:98)
at index.js:395
On Etherscan.io I get this additional error message under 'Status':
Fail with error 'AssetContractShared#_requireMintable: ONLY_CREATOR_ALLOWED'
Here is the smart contract function I'm calling. It works fine when I remove the for loop with the Opensea(openseaSharedAddress).safeTransferFrom(msg.sender, burnAddress, oldIds[j], 1, ""); function
function batchMigration(uint256[] memory oldIds, uint256[] memory newIds, bytes32[] memory leaves, bytes32[][] memory proofs) external {
for (uint i = 0; i < oldIds.length; i++) {
// Don't allow reminting
require(!_exists(newIds[i]), "Token already minted");
// Verify that (oldId, newId) correspond to the Merkle leaf
require(keccak256(abi.encodePacked(oldIds[i], newIds[i])) == leaves[i], "Ids don't match Merkle leaf");
// Verify that (oldId, newId) is a valid pair in the Merkle tree
//require(verify(merkleRoot, leaves[i], proofs[i]), "Not a valid element in the Merkle tree");
// Verify that msg.sender is the owner of the old token
require(Opensea(openseaSharedAddress).balanceOf(msg.sender, oldIds[i]), "Only token owner can mintAndBurn");
}
for (uint j = 0; j < oldIds.length; j++) {
Opensea(openseaSharedAddress).safeTransferFrom(msg.sender, burnAddress, oldIds[j], 1, "");
}
}
And here web3 part where I call the batch migration function:
await smartContract.methods
.batchMigration(oldIds, newIds, leaves, proofs)
.send({
from: walletAddress, //accounts[0]
gasLimit: 6721975,
}).on('transactionHash', function (hash) {
console.log(hash)
});
Before I'm calling the batch migration function I'm setting ApprovalForAll, so this shouldn't be the problem:
await openseaContract.methods.setApprovalForAll(SMART_CONTRACT_ADDRESS, true).send({
from: walletAddress,
});
Has anyone an idea why this error occurs?
Thanks
I was having the same problem and after testing a bit, I could find a solution.
As I've just posted here https://ethereum.stackexchange.com/questions/111077/error-execution-reverted-assetcontractsharedcreatoronly-only-creator-allowed, the contract is calling the minting function before transferring the token. Calling the minting function leads to the call to a modifier, that itself checks the tokenOwner.
The solution is to check if the token has been minted and mint it, before it can be transferred by the other address (that has been approved).
test the balance of the token
if it has no balance, mint it first (from the transferring account)
then you can setApprovalForAll
then the transfer should work

connect to trustwallet and get bsc, eth, btc addresses and balances

right now I use this code:
https://github.com/Web3Modal/web3modal-vanilla-js-example
but it connects only eth address from trust wallet
I tried to change provider options to this:
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
rpc: {
56: "https://bsc-dataseed.binance.org/"}
}
},
But didn't work
In my trust wallet I have btc address, eth address, bnb address and I want to know all this addresses and balances. But right now I can only get eth address
I tried to do this:
const chainId = 56//await web3.eth.getChainId();
// Get list of accounts of the connected wallet
const accounts = await web3.eth.getAccounts();
But this gives me only eth accounts.
So what do I do?
You need to ask the user to change the chain in the wallet itself to get access to accounts on different chains. Currently there is no API or way to force the user t change a chain.
In my case, it worked on Trust wallet, and did not work on metamask mobile app:
walletconnect: {
package: WalletConnectProvider, // required
options: {
rpc: {
56: 'https://bsc-dataseed.binance.org/',
97: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
},
network: "binance", // --> this will be use to determine chain id 56
},
},
I'm not sure the bellow code is required:
web3Modal = new Web3Modal({
network: 'binance', // optional
cacheProvider: true,
providerOptions, // required
})
You can find out how to configure by reading the source code directly:
// Select BSC work on Trust wallet but dont work on metamask
https://github.com/Web3Modal/web3modal/blob/72596699b97d231dfaa5ef04110b61b8dc77d57d/src/providers/connectors/walletconnect.ts#L30
https://github.com/Web3Modal/web3modal/blob/72596699b97d231dfaa5ef04110b61b8dc77d57d/src/helpers/utils.ts#L198

Default account for Ropsten deployment using truffle-hd-wallet

I'm trying to deploy a custom ERC20 Token to Ropsten network by using truffle-hd-wallet. The transaction was went well, however, the weird thing was the newly deployed custom ERC20 token main holder account it wasn't my desired account but an unknown account. When I added the token to my own Ropsten account the amount is ZERO which supposed to have the initial values. Is there a way I can set my desire deployment contract address to the truffle? Please advise.
Thank you.
Desire Address : 0xd61794624e9542495A72Cfac7Cc10B4275b8f8E5
Actual Address : 0xEDD4C3676c8579D25463040fd196626a9B7C60a2
ropsten: {
provider: function() {
return new HDWalletProvider(MNEMONIC, "https://ropsten.infura.io/v3/" + INFURA_API_KEY, 0);
},
network_id: 3,
gas: 4700000
}
},
module.exports = function(deployer) {
deployer.deploy(CToken).then(function () {
let walletA = walletAaddr;
let walletB = walletBaddr;
return deployer.deploy(
CTokenSale,
CToken.address,
walletA,
walletB
).then(function () {
// token ownership setting
CToken.deployed().then(function(instance) {
let fptc = instance;
return fptc.transferOwnership(CTokenSale.address, {gas:1000000});
}).then(function(result) {
console.log("transferOwnership successful!")
}).catch(function(e) {
console.log("Ownership Transfer failed!")
});
CToken.deployed().then(function(instance) {
let fptc = instance;
return fptc.transfer(CTokenSale.address, 100, {gas:1000000});
}).then(function(result) {
console.log("Sales Token Ready!")
}).catch(function(e) {
console.log("Sales Token failed to deploy!")
});
});
});
};
You haven't included your token smart contract code. I assume that the account deploying the tokens either is given the initial supply, or has a minter role.
I suggest you confirm that the first account derived from your 12 word seed phrase (mnemonic) is the address that you want: e.g. 0xd61794624e9542495A72Cfac7Cc10B4275b8f8E5.
You are specifying the first account with 0 as the address_index.
With Truffle HDWallet Provider you can specify a derivation path if you are using something different from the default.
https://github.com/trufflesuite/truffle/tree/develop/packages/truffle-hdwallet-provider
I recommend reading the OpenZeppelin documentation (if you haven't already) on:
Tokens: https://docs.openzeppelin.org/v2.3.0/tokens
Crowdsales: https://docs.openzeppelin.org/v2.3.0/crowdsales
You can also ask questions at:
Ethereum Stack Exchange: https://ethereum.stackexchange.com/
Zeppelin Community Forum: https://forum.zeppelin.solutions/

web3 contract method isn't being called

I have the following fragment of code that calls a contract method using web3 and for some reason when Metamask opens up and I click confirm to send the transaction, nothing happens. Metamask just keeps loading and says transaction approved. Also, the callback function isn't being executed. Why is this happening?
contractInstance.buy(price, seller, {
from: web3.eth.accounts[0],
value: price
}, (err, txHash) => {
//do something
})