7

Turns out transaction receipt logs only include events emitted in the context of the direct contract function being called. If the called function makes another call to a separate external contract that emits an event, those won't be included even if there are emitted. To make use of those emitted events from other contracts: const sha3 = require('js-sha3')...


5

This line is wrong: var web3 = new Web3.providers.HttpProvider('http://localhost:7545'); You're instantiating a provider instead of instantiating Web3. It should be this: var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));


4

You can now use the web3.eth.abi.decodeLog function (web3 1.0). Example from the documentation: web3.eth.abi.decodeLog([{ type: 'string', name: 'myString' },{ type: 'uint256', name: 'myNumber', indexed: true },{ type: 'uint8', name: 'mySmallNumber', indexed: true }], '...


4

Due to the limitation imposed by Number.MAX_SAFE_INTEGER, try to stick to the following rules: Rule #1: Avoid using toNumber() on any value returned from a contract function whose return-value type is one of the following: uint64 uint128 uint256 This also applies for public variables (since the compiler generates implicit getter functions for them). ...


4

If I understand correctly your want to upload a file from the client machine to the web application using the standard HTML tag <input type="file"> and then hash the content of the file. Your code is actually hashing the full path of the file. If you want to read the content of a file, I recommend to use FileReader like this: HTML: <div> &...


3

Web3.js uses the BigNumber library since JavaScript does not do a good job handling large numbers correctly. Take a look at the following examples on how you can recover the value you expect: var val; web3.eth.getBalance('0x90b0137bf6ddb130ed8e3f28cc9f929b0b609ed2', function (error, wei) { if (!error) { val = wei } }) val > Object { s: 1, e: 17, c: (2) ...


3

Thanks for this! Ended up doing: node --stack-size=4096 .\node_modules\truffle\build\cli.bundled.js compile, instead of truffle compile (after taking a look in node_modules/.bin/truffle). EDIT: on Ubuntu this works too: node --stack-size=4096 node_modules/.bin/truffle compile


3

As per the web3 docs: myContract.methods.myMethod([param1[, param2[, ...]]]).call(options[, callback]) Truffle and Ganache inst.methods.multiply(2).call() .then(function(result) { console.log("r-->"+result); }) .catch(function(err) { console.log("err-->"+err); } ); Or, simpler: inst.methods.multiply(2).call()....


3

I am not sure how you installed ethereumjs-tx , but you can check that in your package.json file. If you don't see ethereumjs-tx there means your app is not using that module even if it is installed. You can install it with :- Run you cmd as administrator and navigate to folder where all files of project are there and run this command :- npm install ...


3

There are two main issues here: require is a part of the Node.js module system, and will not work on standard HTML page, nor do you need it. The function you want to call to get the current block number is web3.eth.getBlockNumber(), which is an asynchronous function, so you will also need to handle that. Your code will work if written like so: <script ...


3

While Aquila's answer can work as a workaround, the way truffleAssert.eventEmitted() works is by applying a filter function on the event's arguments. The drawback of this is that you can't "assert" each argument individually, but this will allow you to run both assertions in this fashion. I saw from your other question that you're using Truffle v5 with ...


3

Sincerely this cannot be a major item if you design your code in a structured way. It seems probable that you use a different sw design paradigm from that for which REMIX has been designed. In that paradigm, the ABI should change very rarely because it specifies the external interface surface of the code. If not, it could means that you change your system ...


3

You can call getCode (web3.eth.getCode(address)). The call will return 0x if it selfdestruct'd. Note that this isn't a positive way to know it selfdestruct'd, it'll also return 0x if it's an EOA or the contract was created with no code.


2

I'm also facing same problem. My ganache was running, metamask is also running, web3 is also injected. The problem was web3.eth.accounts and web3.eth.getAccounts().then(...) was returning null. But after lot of searching I found that ethereum.enable() I run this command and one metamask popup was opened, which connected my metamask account to app.


2

You need to make sure that you are exporting everything correctly from your compile.js file to your test file. I have spelling error when I was exporting contract, my code bit here module.exports = solc.compile(source, 1).contracts[':Registration']; the registration was :registration instead of :Registration and hence the {interface, bytecode } were not ...


2

Try this: var friendinstance; FriendContract.deployed().then(function(instance){ friendinstance = instance; return friendinstance.getFriend(); }).then(function(result) { console.log(result); var str=result.toString(); var friendDetails=...


2

dApps must now request access to user accounts by calling a new method on the provider: ethereum.enable() more details here https://medium.com/metamask/https-medium-com-metamask-breaking-change-injecting-web3-7722797916a8


2

Just do: inst.multiply(2,function(err,res){console.log(res)}) Hope this helps


2

Web3js is a native js library to interact with block chain and smart contract then you can freely choose any to build your frontend


2

Even thought they have similarly confusing names, they refer to different things. The format { key: value } is web3 format for providing extra meta data for the function. Those are not passed on as parameters for the function but are handled internally. For example the key from can be used to define from which of the available accounts the transaction is ...


2

First declaration of truffleAssert.eventEmitted handles all events, that is why you have the issue. It means you need to assert all events in single truffleAssert.eventEmitted or you can use workaround like: it("should check that the correct events are returned", async () => { let result = await contractInst.messages({from: user1}); ...


2

Thank you for using my truffle-assertions library. Apparently this was caused by a bug in the function. I fixed the bug, and published a new version 0.7.1 to npm that you can use. Using this version should fix your issue. If there are any remaining issues, please open an issue on the repository.


2

It's rather a JS question, but anyway, here the answer, since it's useful to know when writing Ethereum tests in JS: The problem with your second code fragment is that your test case is considered as done before your "then"-part is executed. I would recommend to try not to mix async/await and then as far as possible. Variant 1 (no async function, return ...


2

This is a bit convoluted since Web3 does not directly expose events emitted by a transaction, but it can be queried by tracing the transaction. Trace transaction : https://github.com/ethereum/go-ethereum/wiki/Management-APIs#debug_tracetransaction It will return a block of info for each instruction of transaction. (PUSH1 in this example) { depth: ...


2

If it's Web3 1.x, it's a promise. Try: > var accounts; > web3.eth.getAccounts().then(function(response) { accounts = response; console.log(accounts[0]; }); Hope it helps.


2

This is a pattern I use as well to test Oraclize callback functions. I'm using something like this in a presentation at EthCC next week, so today I had to figure out how to do this in newer versions of Truffle. I ended up doing the following: const getFirstEvent = (_event) => { return new Promise((resolve, reject) => { _event.once('data', ...


2

That's a Node question, not a Truffle question, but you can do this in two steps: Step 1 - create file common.js and initialize your common stuff in it, for example: module.exports.myVal = 42; module.exports.myFunc = function(x) {return x;}; Step 2 - import and use this file in your Truffle tests, for example: const common = require("./common.js"); ...


2

If you are using web3, you could easily sign any transactions or just messages: https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#sign If you don't want to use web3 (for example because you dont want to initialize with an ethereum endpoint), you can find some alternatives: https://docs.ethers.io/ethers.js/html/api-wallet.html https://github.com/...


2

The callback is returning the transaction hash. Instead, I suggest you to use "promise" or ".on" to get the receipt as documented in the package document https://web3js.readthedocs.io/en/1.0/web3-eth.html#sendsignedtransaction It would look like something like: // Broadcast the transaction web3.eth.sendSignedTransaction(raw) .on('receipt', console.log); ...


2

Web3.js returns all uint types as BigNumber objects. If you want to get the decimal string which represents the numeric value embedded in a BigNumber object, then you can call function toFixed on that object. For example: const [reward, length, votersCount, manager, pollActive] = await myContract.methods.getSummary(); console.log('reward:', reward....


Only top voted, non community-wiki answers of a minimum length are eligible