Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now
8

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

In the new version you should change const Tx = require('ethereumjs-tx') to const Tx = require('ethereumjs-tx').Transaction


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> &...


4

The output you receive is in hex format. You need to conver hex to an int. Here is the full code you need to use: const contractInstance = web3.eth.contract(contractAbi).at(contractAddress); const total_supply = parseInt(contractInstance.totalSupply.getData()); console.log(total_supply); I added parseInt() to convert your hex number into a human readable ...


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

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.


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

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

First, import web3 as such: const Web3 = require('web3') Then instantiate a variable (in my case web3) and set a provider: const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/INFURA_ACCESS_TOKEN:8545')) Then you can use all the available web3 methods. Hope it helped you!


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

Per this comment on solc-js issue #31, you can append this stanza to package.json. "jest": { "testEnvironment": "node" } (which I guess tells jest to run in node, which will bring in the things that solc needs).


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

You may notice in the comments, I was unable to work out what wasn't working for me, but not a fan of "it works, thanks" answers which don't help others. So I have put a working example up on gists for anyone who is looking for this. Just need to make some changes to be specific to your situation, but should be relatively straight forward. https://gist....


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

For web3.js 1.0, I got it working like this: In head: <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.34/dist/web3.min.js"></script> Then get a reference to it: <script> var web3js = new Web3(new Web3.providers.HttpProvider('https://testnet-rpc.gochain.io')); </script> And use it like this: var contract = ...


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

Try changing on for once var myContract = new web3.eth.Contract(_abi, senderAddress, options); const toDeploy = myContract.deploy({ data: _bytecode, arguments: [100000, "0xD41396Fa287B20311DD389D563539d8578dad23e"] }); toDeploy .send({ gas: 5000000, from: myAddress }) .once("confirmation", (confirmationNumber, receipt) => { //After several ...


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....


2

check this question - https://stackoverflow.com/questions/5786851/define-global-variable-in-a-javascript-function If web3 is not defined as a global variable, but you have "web3 = new Web3(web3.currentProvider)" inside a function - the web3 object will be local for that function only, while with window.web3 it will be globaly accessible


2

In web3.js v0.x: The expression contractInstance.totalSupply.getData() would get you the encoded ABI data (byte-code) of a call to function totalSupply. In order to actually call the function and retrieve the return-value asynchronously, you should use: contractInstance.totalSupply.call().then(total_supply => { console.log(total_supply); }); In ...


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