New answers tagged

0

Have you tried reading the docs on the @truffle/contract docs? https://www.npmjs.com/package/@truffle/contract There are several steps to do before including the truffle-contract.min.js file in the index.html.


0

Here's how you add an existing account, if you have the account's private key and password: const account = web3.eth.accounts.privateKeyToAccount("0x" + YOUR_PRIVATE_KEY); await web3.eth.personal.unlockAccount(account.address, YOUR_PASSWORD);


1

Both web3js and web3php are just libraries to communicate with the Ethereum blockchain. You can ask through a browser (then you'd use web3js), or from a server (then you'd use web3php), some information (like, what's the balance of this address, or call some contract's method to read something).


0

This is resolved: It returned 'e' as an int object, so I use an array to take 'e' as an index. const sta = ['Active', 'Refunding', 'Pending', 'Releasing']; (new PaypalContract()) .releasePayment(action.id) .then(() => (new PaypalContract()).getState(action.id)) .then(function(e) { ...


0

Transaction is failed because the gas limit you allocated in Metamask is less than what required. When we compare, _init() consumes gas more than revert(). So, you need to set gas limit of transcartion as much as necessary in the part indicated in the photo: Good Luck.


0

Here is the answer to your problems: web3.eth.defaultAccount is deprecated in modern dapp browsers and that's why you get missing from property error. You can read more how to solve this here. Method eth_sendTransaction is not supported by the Infura provider. Why your reading methods are working and the transfer method is not? Because for reading the ...


0

To call a contract fallback function you can use the below way using Javascript: Consider I have to call a set function that has a uint256 as a parameter. const demo = await Demo.new(); const valueToUpdate = 1234; const signature = web3.utils.sha3('set(uint256)').slice(0,10); const msgData = signature + web3.utils.toHex(...


0

Because all Erc20 tokens have same rules, you can create your own ERC20 token. I have published an article to explain it in step by step tutorial. you can find it here: https://athamidn.medium.com/step-by-step-get-erc20-test-token-faucet-on-ropsten-d20850375f2c


2

MetaMask does not provide a way to get the private key through code by design. Any interaction with accounts in MetaMask has to be done through the Web3 API, to prevent a (malicious) website from stealing a user's private keys.


0

//set web3 variable const web3 = new Web3(window.ethereum); //get all the accounts const accounts = await web3.eth.getAccounts(); //if you're using react this.setState({web3, accounts}); //send the tx using react this.state.web3.eth.sendTransaction({to: contractAddress, from: this.state.accounts[0], value: ETHamount}); or if you're not using react web3....


0

I have found the answer with the help of this post as well: Deploy smart contract with web3 and ganache-cli I was missing .object from the bytecode incorrect: .deploy({data: evm['bytecode'], arguments: ['Hi there!']}) correct: .deploy({data: evm['bytecode'].object, arguments: ['Hi there!']}) suggestion: it is better to append '0x' in bytecode like: .deploy({...


1

The concept of decimals is purely for user-friendliness - inside the blockchain there are no decimals. That's why it's optional. If there are no decimals then you simply display what the token amount inside the contract shows - things get easier than with decimals. So it behaves like decimals was 0. This concept is rather confusing for many people. You can ...


0

In step 1, the user just transfers to your contract in the ERC20 token contract. Your contract is not even aware this transfer took place. In step 2, the user buys some token X from your contract, for a price, and your contract sends the tokens, if the contract has enough, or the transaction fails and the funds are returned to the user, which is what you ...


0

Not sure why the default gas estimate from web3 -> metamask was so high, but I have gotten around this by using the estimated gas from estimateGas() + a buffer to manually set the gas sent in the depositAll transaction. Here is the code: const depositHelper = new web3.eth.Contract( DepositHelper.abi, // abi for DepositHelper contract '...


0

Turns out this is trivial to do in web3js but ethersjs does not offer any functionality to do it. In web3js: myContract.events.MyEvent() .on("data", async (error, event) => { myDatabase.insert(event); }) .on("changed", async (error, event) => { // Called when event is no longer valid myDatabase....


2

For an array, you'll need to add a function in your contract, for example: uint[] private someArray; function getSomeArray() external view returns (uint[] memory) { return someArray; } For a mapping, you'll need to extend your contract design, for example: Every time you add/remove an item to/from the mapping, also add/remove that item from/to an array ...


0

The issue was that I need to pass a transaction to the estimateGas() function. In addition, I needed to delete the data and to fields from the transaction dictionary (if they exist). Final Working Code: from web3 import Web3, HTTPProvider web3 = Web3(HTTPProvider('https://mainnet.infura.io/v3/{LONG_INFURA_PROJECT_ID}')) # grab contract instance using web3 ...


0

I had bad imports: from web3 import Web3, HTTPProvider, IPCProvider, WebsocketProvider from web3.auto import w3 Fixed imports: from web3 import Web3


0

What you are doing looks correct. Basically, if privateFor is missing, then the transaction is public. You must specify privateFor in order for the transaction to be private. All the nodes specified in privateFor (plus the local node) will become participants in that private transaction. Any attempt to access the contract, or the state, from a non-...


0

I was searching this today. Try provider.getNetwork().chainId. getNetWork().name gives human readable name like 'homestead'


0

You have two possibilities a) your own build script or b) just use truffle framework. The first option is strait forward but has some drawbacks. When you start with writing contracts it is a good idea to understand the way the sol compiler works, but later the truffle framework helps you to manage more complex scenarios (i.e. like migrations, testing, ...


0

Apparently this used to happen on the ropsten network. I got it today from a light node on ropsten, even though the transaction had 10 confirmations. It is possible that the getTransaction() request was sent to a peer which was a little bit behind? Anyway, since this seems to be a rare and temporary issue, my solution has been to use a wrapper function that ...


1

You can look into https://app.gitbook.com/@arkane/s/widget/ Arkane allows you to easily integrate your app with several blockchains, whether you already have an app integrated with web3 or are building a new application from scratch.


0

getPastEvents('Transfer', ...) There is no event Transfer in the contract that you've linked. So this attempt will obviously not retrieve any information from the blockchain. BUSD choosing to fire events in a non traditional manner. There is no such thing as "fire events in a non traditional manner". Perhaps you meant to say "BUSD does not ...


0

If the user is using MetaMask: MetaMask has said that it will deprecate injecting web3 into the global object. However they have replaced this with an ethereum object which is equivalent to web3.currentProvider. Since 2018, it has become necessary to request permission to get the current user's account address, which can be done by making a call to ethereum....


1

Do you know the MultiSender app? It allows for multiple Ether and ERC 20 token transactions to be bundled in one transaction. It's open-source on Github rstormsf/multisender in case you want to review the logic. There's also a more detailled write-up on Medium: MultiSender — Send Ether and Ethereum Tokens to Multiple Ethereum Addresses In A Single ...


0

Looks like Metamask added functionality for this. You can use their following API commands: getEncryptionPublicKey(address) & decryptMessage(address, data)


2

I discovered the same issue. It's a known bug in web3.js v1.3.0 that was brought in this PR: #3649. In this comment someone explains it in more detail. There is an ongoing PR here that will fix it, so i'd suggest to keep an eye on that one. A temporary solution would be to downgrade to web3 v1.2.11


2

Every transaction in a block is processed at the exact same time. If you have the transaction information (which is the data you posted), you can use the blockNumber to look up the block information with getBlock() and find the timestamp of the block (which is also the timestamp of the transaction). In your case, you would simply call: web3.eth.getBlock(...


1

You're thinking is heading in the right direction. A contract cannot monitor event logs so that activity needs to be off-chain. Using off-chain processes to identify opportunities has advantages - computing capacity, off-chain inputs, maintenance/optimization of the algorithms, cost, etc. Many (most) attack strategies require transaction atomicity. That is, ...


1

The bots are continuously listening to both onchain changes (events, transactions, etc) and offchain changes (for example, price changes). Whenever they find that the time is right, they send a transaction to one of their already-deployed smart contracts, or possibly even deploy a new smart contract. In both cases, the desired set of operations is performed ...


0

You need to increase the transaction data size, not the code size. The transaction data size can be increased on Quorum with the genesis txnSizeLimit value (up to 128kb). This is documented here: https://docs.goquorum.consensys.net/en/latest/HowTo/Configure/GenesisOptions/#configurable-transaction-size


2

It's an invalid deposit. The deposit contract cannot verify the deposit signatures yet. This might change with the Berlin hardfork though if we can get a BLS precompile. But that's not set in stone yet. Currently, the EVM is unable to process the BLS signature of the deposit data. This has the (im)practical consequences that Ethereum 2.0 clients (and other ...


0

In the case your node is syncing, then do: this.web3.eth.isSyncing((error: Error, sync: any) => { if (!error && sync) { console.log(sync.currentBlock); console.log(sync.highestBlock); } });


0

I don't know about the docs, but the code in Geth has a two line comment over here: https://github.com/ethereum/go-ethereum/blob/master/console/bridge.go#L330 Here's the quote: // SleepBlocks will block the console for a specified number of new blocks optionally // until the given timeout is reached. Hope that helps!


0

The "Returned error: query returned more than 10000 results" error is a general limitation of infura.io. In the case you get more than 10000 events with your request, this message will be returned and you get no result. But, there is a solution. Implement a kind of fork and join for your query. In the case you get the message split the from block ...


0

So the indexed event parameters for the Transfer Event for USDT is actually from and to instead of src and dst. When I switched to the correct parameters, I started receiving a normal quantity of events. When I failed to use the filters correctly, it just sent me every Transfer event in the contract. I thought that all ERC20 tokens would have the same ...


0

Change parameter Value in object txObject to value ( without capital letter ). Silly mistake, but happens a lot :)


0

This is a possible method, directly calling the JSON RPC method personal_listWallets: async function listWallets() { try { const result = await sendRPC_personal_listWallets(); console.log(typeof result); return result; } catch (e) { return e; } } function sendRPC_personal_listWallets() { return new Promise((...


1

getBalance is asynchronous, so you can't assign a variable in the callback and expect that variable to be set in synchronous code after that. You can move any code that requires the balance into the callback of getBalance, e.g.: web3.eth.getBalance(address, (err, bal) => { if (err) { // Do something with the error return console.error(err); } ...


0

Try respecting the ethereumjs-tx format for the transaction parameters. Example from their doc (https://github.com/ethereumjs/ethereumjs-tx) : const txParams = { nonce: '0x00', gasPrice: '0x09184e72a000', gasLimit: '0x2710', to: '0x0000000000000000000000000000000000000000', value: '0x00', data: '...


Top 50 recent answers are included