New answers tagged

0

import contract from 'truffle-contract' but, node this file will report error 'SyntaxError: Unexpected identifier'


1

You can achieve that by using web3.eth.abi.decodeLog(inputs, hexString, topics);. The first parameter inputs must include the properties of the event from your smart contract, second one hexString is the bytecode of the event and the third topics is array containing the topics. Read more here.


1

1) Using Indexed parameters e.g address or integers can also be very useful Examplen using ERC20.solcheck here Erc20.transfer should emit event(address _to, uint256 _amount) which can be indexed thus making it easier to filter at the front end event Transfer(address indexed _to, uint256 _amount); contract events could be written this way, and you get ...


1

import Web3 from 'web3'; At the top of the file and then during a componentwillmount or whatnot, these lines... window.web3 = new Web3(window.ethereum); await window.ethereum.enable();


1

Here is a working js script example of your contract: var Web3 = require('web3') let abi = [ { "constant": true, "inputs": [], "name": "fname", "outputs": [ { "internalType": "string", "name": "", "type": "string" } ], "payable": false,...


1

In your working example, you are handling the result of getAccounts in an asynchronous manner: web3.eth.getAccounts().then(console.log); In your non-working example, you are wrongfully assuming that it runs synchronously to completion: var acc=web3.eth.getAccounts(); Function web3.eth.getAccounts returns a Promise object which, when resolved, contains ...


0

I solved it! The answer is really simple, but maybe I can help someone else by sharing the solution. I did not send back a receipt of the request from the client. I added the line: res.send("Data received!"); I put it just before the end of the POST after looping through all the records received. I have also updated the code above to reflect this. Easy ...


0

I have seen this when calling the same contract method twice from JavaScript without waiting for the first call to finish by either await or calling a second time in the success callback. My guess is that contract methods in web3js are not thread safe.


0

use await and let web3 load all the addresses before it produces the result


1

Try this and let us know the result: var Commons = artifacts.require("./Commons.sol"); contract("Commons", function(accounts) { it('should revert the transaction of getBalancePeriod if conditions are not met', function() { return Commons.deployed() .then(function (instance) { return instance.getBalancePeriod(5); }); ...


0

The accepted answer will only work for txn to a contract. For detecting ether transfers ( txn to EOAs ) you'll have to setup a listener for getting latest blocks & query on the transactions array of the block to find a match for a particular requirement.


1

There are two issues with your code. The first one is preventing the contract to be deployed: you must pass the "from" address whenever you send a transaction to the blockchain (as opposed to a call). So, the instantiation should look like this: myContract.new("0x20...31", "0x20...65", { from: provider.getAddress() }) The other issue is that you are not ...


Top 50 recent answers are included