Questions tagged [typescript]

Typescript is a superset of JavaScript and adds optional static typing to the language.

Filter by
Sorted by
Tagged with
9
votes
4answers
4k views

How to use web3.js@1.0.0-beta34 with TypeScript?

Here is a minimal code for testing: import * as Web3 from "web3" const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545")) const main = async () => { const blockNumber = ...
5
votes
1answer
557 views

Alternatives for Truffle for running and writing tests

Truffle offers many conveniences for writing tests for Ethereum smart contracts. The benefits include no need for a separate chain process like Ganache, complex automation of linking and deploying of ...
4
votes
2answers
2k views

TypeError: web3_1.default is not a constructor

I'm trying to convert a DApp that uses web3.js from JavaScript to TypeScript, but I have encountered a bunch of runtime errors. I'm using Visual Studio Code IDE, and I'm compiling to ES6. I've reduced ...
3
votes
2answers
5k views

Getting Metamask account's balance using fromWei

Using web3 javascript code to get selected account's balance in Metamask and show it in html, web3.eth.getCoinbase(function(err, account) { if (err === null) { App.account = account; $("#...
3
votes
1answer
342 views

How to mock an ethers provider while testing with jest?

In the real app, I'm using the web3-react hook to inject the provider, etc. How do I best mock that/replicate that in a Jest Typescript environment?
3
votes
2answers
4k views

How can I use web3.js with Angular 2

I'm trying to import Web3 to my component files which is written in Typescript but I couldn't make it. I used npm install --save web3-typescript-typings and added "include": [ "../node_modules/...
2
votes
1answer
227 views

How to import the Contract type from the web3.js library?

Here's how I can do that in ethers@4.0.47: import { Contract, ethers } from "ethers"; const contractInstance: Contract = new ethers.Contract(address, abi); But in web3.js@1.2.8 none of the ...
2
votes
2answers
36 views

Trying to use window.ethereum.request in Typescript errors out with Property 'request' does not exist on type 'EthereumProvider'

Except for one unanswered question from last November, I cannot find anything . . . . I am revamping some typescript code (in Visual Studio) for the Metamask January change. Previously, I was using ...
1
vote
2answers
29 views

uint16 conversion issue

So I want to test this Solidity code using Typescript but faced with a type conversion issue. uint16 base; function addNumberToBase(uint16 number_) { // This number must be between 1 ~ 5 ...
1
vote
2answers
19 views

String to Hex in Ethers.js

Only one question: How can I convert string to hex in ethers.js I need some alternative to: web3.utils.utf8ToHex() - but in ethers Any help is appreciated
1
vote
1answer
72 views

Calling transfer returns true but doesn't perform the transfer

I have the following simple transfer method in my contract to transfer my erc20 token to another account: function transfer(address to, uint tokens) public returns (bool success) { balances[msg....
1
vote
1answer
78 views

Trouble with web3.eth.Contract, ABI usage with Typescript

I am having a bit of trouble using web3.eth.Contract with Typescript.. import * as ERC721ABI from "../ABIs/ERC721.json"; import Web3 from "web3"; ... const contract = new web3....
1
vote
1answer
22 views

Network configuration for Fortmatic on 'ropsten' — typescript

So I am trying to configure the the ropsten network by injecting the fortmatic provider into web3, but am getting these errors. My code is exactly how they have it in their documentation, so idk why I ...
1
vote
0answers
205 views

window.ethereum.request does not exist on type “isMetaMask, on, removeListener”

It might be a pretty simple question for most, but how do I use the request method on window.ethereum if it does not exist? I see all sorts of properties and methods in the metamask docs, but when I ...
1
vote
0answers
24 views

Typechain and Batch Requests

I'm trying to send a batch request of transactions to my contract from web3. Using Typechain, my contract's methods are of type NonPayableTransactionObject<void>, which doesn't appear to support ...
1
vote
1answer
27 views

Library for Ethereum types?

Is there a library for Ethereum types, for tests written in TypeScript? For example, an address type would be better to use instead of a generic string for Ethereum accounts.
1
vote
0answers
127 views

What is the easiest way to write truffle tests in typescript?

I read about Typechain, but the configuration is rather verbose and generally feels like a very custom solution: Everytime you change contracts you need to run yarn generate.
1
vote
0answers
323 views

Problem with web3.eth.personal.ecRecover

I'm using web3 v1.0 beta33 ethereum packages to do some signing and address recovery in a javascript/Angular5 app. I picked this version because I didn't see this function in 0.2x web3 versions' ...
0
votes
0answers
14 views

Test contract private and internal function

I'd like to test a contract private/internal function. I used to inherit the contract and test it with truffle but that involved Solidity test files. Can I do the same with my current stack (hardhat/...
0
votes
0answers
21 views

Truffle migration with TypeScript

I've been able to run truffle tests successfully using TypeScript, but when it comes to migration, I get stuck. 1) My current setup: tsconfig.json { "compilerOptions": { "...
0
votes
1answer
42 views

How to extract signature from web3.eth.sign or web3.personal.sign

In React Typescript (.tsx file), I'm trying to use web3.eth.sign to validate an account. The signature is being generated properly, but I can't seem to get the signature out of the callback function. ...