8

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


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


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

The issue with getBalance2 has to do with the asynchronous web3.eth.getBalance call. You need to make the entire function async and make that call await in order to correctly return a value to your callsite. The return wei line inside the callback is only returning from the callback, it does not propagate out as the return value to getBalance2. I think a fix ...


3

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


3

If you're using Web3 v1 then you can use web3.eth.getTransactionReceipt(tx). It returns logs property as a part of a result. You can categorize events by looking at their topics property. Sample getTransactionReceipt result: { "transactionHash": "0x7e2e90d913246933b30049c568d9a9768eca5be6fed331656458c2a479f30908", "transactionIndex": 0, "...


3

Solidity's syntax has some similarities to JavaScript, and a large amount of tooling has been written in JavaScript. However, I would not say that knowledge of JavaScript is an absolute prerequisite. ethereum.org maintains a list of language specific resources that you may find useful: https://ethereum.org/developers/#language-specific-resources


3

I teach and develop courseware for B9lab. There is no absolute requirement for JavaScript knowledge and I would argue that similarities between Solidity and JavaScript are superficial. There is much to unlearn, in any case, because blockchain platforms are unlike any other form of software regardless of syntax. External to the blockchain there is always a ...


3

Why not do something like: OraclizeContract.deployed().then(function(instance, fromAddressX) { console.log("Initializing"); instance.deposit({from: fromAddressX, gas: 3000000, .... This way you would pass the fromAddress you want as an input argument to your function. document.getElementById("fromAddress1").addEventListener(...


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

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

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

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

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


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

Your Bytecode isn't a hex number. Prepend a 0x. For example 0x606060405260018054600160a060020a031916... EDIT: Nevermind you already did that. Here is another try. Convert the string to hex. parseInt("0x6060604...", 16) Take note of the radix 16. Leave this value unchanged.


2

With web3.js v1.2.x, you can use function web3.eth.abi.encodeFunctionSignature: const selector = web3.eth.abi.encodeFunctionSignature({ type: "function", name: yourObj.funcName, inputs: yourObj.params.map(param => ({type: param})) }); Or simply: const selector = web3.eth.abi.encodeFunctionSignature("getSupplyRate(address,uint256,uint256)"); ...


2

Ganache can be configured to mine new blocks on a specific time interval. With this setting enabled you are able to include multiple transactions in a single block. To enable this functionality in the GUI, access the settings by clicking the gear icon in the top right corner. Choose "Server" settings. From there you will be able to disable auto-mining and ...


2

Run it again. More generally, run it inside a try/catch block until success. For your specific error, it is possible that the node is not synchronized with your account's current nonce, so you may want to add this to your options object: nonce: await web3.eth.getTransactionCount(0xYourAccountAddress) Since you may also encounter other types of errors, I ...


2

Have you unlocked account1 on Infura? Of course, that's not possible (and you wouldn't want it to be either). This mode of operation is available only when you're using your own private node, so that others will not be able to exploit your account. And even then, it is not a recommend mode of operation, since anyone hacking your node will be able to ...


2

Try to work with ganache-cli instead of ganache-gui. We faced similar issues with our integration tests - lots of transactions are very slow with the Ganache GUI (especially unter Windows the UI has update problems). The command line interface ganache-cli is much more stable and runs in terminal as well as in docker container. From the functional point of ...


2

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


2

if I finish following the tutorial and build a signed TXN with these wrong R+S values, the txn works This seems to suggest the signing by secp256k1.ecdsaSign is correct, but just not deterministic, i.e. it changes every time you sign, even with the same key and data. Notice the tutorial uses private_key.sign_deterministic, so, to produce the same result, ...


1

I'm not the strongest player in this dialect, but this looks familier: await instance.purchaseTokens.call('12'); Try adding transaction arguments (gas, gasPrice, value) like this: await instance.purchaseTokens.call({value: <amount>}); call is probably wrong, so: `await instance.purchaseTokens({value: }); Hope it helps. p.s. If there are ...


1

You should not think of Ethereum transactions in the same sense as regular messaging / transactions / background runs in the "traditional" world. Information like exact timestamps is really irrelevant in Ethereum. A miner picks up transactions for his block and the miner decides in which order the transactions will be executed inside the block. All that ...


1

Comments above gave answer without the syntax. Need the await in the assignment: user1Balances = await GetAndShowUserBalances("before depositToken", "user1", user1Addr)


1

If I make this function without payable and don't take any money from the caller then return value accurately returns me the code. You are on the right track but misinterpreting what you see. I'll break it down. accurately returns me the code I think you mean returns(string memory). without payable Payable has nothing to do with it. You have to ...


1

Since it is private is there a way to replace solidity with vanilla JS? You'd need to write a compiler that could compile JS to EVM bytecode, and I'm pretty sure no one has done that yet. The accepted answer to the following question might help explain the rationale behind developing a new smart contract languages, rather than use an existing language ...


1

Assuming that is a TypeScript compile error, add a file at src/typings.d.ts containing: declare var BrowserSolc: any; That just let's the compiler know that BrowserSolc is a real thing even tho it can't see it (because the TypeScript compiler does not load the scripts in tags).


1

Change it to this: async function run() { const decimals = await contract.methods.decimals().call(); for (var i = 0; i < 8444182; i++) { const balance = await contract.methods.balanceOf(address).call(null, i); const actual = new BigNumber(balance + "e-" + decimals); console.log(actual.toFixed()); } } run();


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