Questions tagged [typescript]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
19 views

Are the Hardhat provided accounts' public keys as accessible as their private keys?

I know that if I run Hardhat node, I will be provided with the addresses and private keys of the Hardhat provided accounts, like this: Hardhat Accounts ======== Account #0: ...
0
votes
1answer
10 views

How to change the scope of a variable in a Hardhat test written in TypeScript?

I am trying to write Hardhat tests with TypeScript and am struggling with the scope of (thus accessing) certain variables. I have provided a simplified snippet of what I am struggling with. Below, is ...
0
votes
0answers
24 views

How to send tether token in ether wallet using web3

I am gonna send tether token from my wallet address to other wallet address using web3. const Web3 = require('web3'); const web3 = new Web3('https://mainnet.infura.io/v3/projectId'); web3....
0
votes
1answer
18 views

How to get Hardhat to log a returned variable rather than the entire transaction receipt? (Test written in TypeScript)

I have a function, fn(), in a contract that returns a variable. I am then testing said function's returned variable value in a Hardhat unit test written in TypeScript. However, when I console.log the ...
0
votes
1answer
8 views

Get mapping value in hardhat

I have a mapping in my contract mapping (uint256 => uint256) totalBoostedPercent; I am using hardhat and typechain to generate type from my contract. In my test file.ts, I tried to access the ...
0
votes
0answers
5 views

How to use bn-chai in a typescript test script?

I would like to use bn-chai plugin for chai in a test script written in typescript. I imported (the official documentation uses require) the dependencies and set chai according documentation: import { ...
0
votes
1answer
64 views

What is the Polygon equivalent of `import { useWallet } from '@binance-chain/bsc-use-wallet'`

I'm following a private code tutorial for building a bsc dapp that calls import { useWallet } from '@binance-chain/bsc-use-wallet'. However my current project is going to be for the Polygon network. ...
0
votes
2answers
297 views

Calculate The Gas Fee Of A Smart Contract Function Call And Convert The Result to USD Value

How Does One Estimate The Gas Fee Of Particular Smart Contract Function Call? I Am Aware Of Using web3.eth.estimateGas How Can One Take This Estimated Gas Result and Depending on Network Connected ...
0
votes
1answer
77 views

Correct Typescript typing for web3 ethereum contract

I'm trying to understand the correct typing I should use for a web3 eth contract that is one of the parameters of my function: import * as express from "express"; import { check, oneOf, ...
1
vote
1answer
96 views

Can't get info with web3: web3.eth.getAccounts returns undefined

I'm trying to connect to the blockchain via web3 and metamask and the web3.eth.getAccounts() method is returning undefined, however window.ethereum.request({ method: 'eth_requestAccounts' }) returns ...
0
votes
1answer
79 views

Dapp with frontend

I made a login page with metamask for my Dapp, but now I need to link my login button to the profile page which will have student details like name, phonenumber, certificates (pdf) etc. where these ...
2
votes
0answers
350 views

Ethers and Web3-React: Cannot estimate gas when trying to connect with contracts deployed on testnet and using Alchemy as node provider

I'm trying to connect with contracts deployed on the Rinkeby testnet using a node provider. When I was testing using hardhat as a local node, the contracts are called with no problem, but when I ...
0
votes
0answers
25 views

How can I pass instance of provider and contract to all of my React components?

I have done the hardhat greeting tutorial found here and it was very helpful. To continue learning, I am building a slightly more advanced project that uses multiple react components. One thing that ...
1
vote
0answers
111 views

Decoding transaction data using abi-decoder

I'm trying to write a very simple script in typescript that finds uniswap transactions and decodes the transaction data so I can read the function being called and the parameters it is being called ...
0
votes
1answer
155 views

What is the equivilent to Solidity's abi.encode() function in Web3 JS?

I have a function in Solidity, that I would like to replicate using Typescript and Web3 function mint( address to, uint256[] memory ids, uint256 indexToMint ) public { ...
2
votes
2answers
466 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
3
votes
1answer
137 views

Test contract internal functions

I'd like to test a contract internal functions. 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/mocha/...
1
vote
0answers
254 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": { "...
2
votes
2answers
2k 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
2answers
57 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 ...
3
votes
3answers
3k 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 ...
0
votes
1answer
234 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. ...
1
vote
1answer
29 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
666 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
80 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 ...
2
votes
1answer
35 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.
3
votes
1answer
620 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 ...
5
votes
1answer
856 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 ...
3
votes
1answer
751 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?
1
vote
0answers
162 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.
5
votes
2answers
3k 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 ...
1
vote
1answer
86 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....
9
votes
4answers
5k 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 = ...
1
vote
0answers
364 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' ...
3
votes
2answers
8k 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
2answers
5k 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/...