| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
													Tags
													
											
												
												- Vue.js
 - SBT표준
 - 머신러닝기초
 - 러스트 기초
 - ambiguous function description
 - redux toolkit 설명
 - vue기초
 - ethers typescript
 - 러스트 기초 학습
 - redux 기초
 - ethers websocket
 - erc4337
 - Vue
 - 오블완
 - 스마트컨트렉트 함수이름 중복 호출
 - cloud hsm 사용하기
 - ethers v6
 - 체인의정석
 - 스마트컨트렉트 예약어 함수이름 중복
 - 계정추상화
 - 스마트 컨트렉트 함수이름 중복
 - erc4337 contract
 - cloud hsm 서명
 - cloud hsm
 - 러스트기초
 - git rebase
 - 컨트렉트 동일한 함수이름 호출
 - 티스토리챌린지
 - ethers type
 - rust 기초
 
													Archives
													
											
												
												- Today
 
- Total
 
체인의정석
ethers에서 bigNumber를 number 형태로 고치기 + 테스트 값 비교 본문
728x90
    
    
      const bigNumberChainId = await exchangeCore.getChainId();
    chainId = ethers.BigNumber.from(bigNumberChainId).toNumber();
다음과 같이 ChainID를 조회하는 경우 bignumber가 나오는 경우에서
위와 같이 bigNumber를 먼저 구한 후 .toNumber()를 해주면 숫자형으로 바뀐다.
일반적인 decimal과 관련된 경우 소수점을 표시하고 싶은 경우 아래와 같이 바꿔서 표시해 줄 수 있다.
How to convert bignumber to normal number using ethers.js?
I am using ethers.js I can't figure out how do you convert a bignumber like 1252500000000000000 to 125.25 -Mike
ethereum.stackexchange.com
ethers.utils.formatEther( value ) ⇒ string
price 0.0000001
* 테스트 시에 주소값을 텍스트 형태로 비교해야 하므로 아래와 같은 chai 문법 사용.
    expect(verifiedAddress).to.equal(signerOne.address);
숫자형일 때는
expect(숫자).equal(숫자);
728x90
    
    
  반응형
    
    
    
  '블록체인 > Ethers & web3' 카테고리의 다른 글
| 스마트컨트렉트 테스트 코드, hardhat & ethers & Typescript에서 상황별 Big number 다루기 (0) | 2022.07.26 | 
|---|---|
| hardhat 테스트 코드에서 beforeEach 사용하기 VS fixtures 사용하기 (0) | 2022.07.19 | 
| hardhat의 chainID를 수정하여 메타마스크와 연결하기, 메타마스크와 hardhat 테스트 네트워크 연결하는 법 (0) | 2022.06.30 | 
| 주소가 CA인지 체크하는 방법 (0) | 2022.06.24 | 
| DocstringParsingError: Documented parameter "" not found in the parameter list of the function. 오류 해결 (0) | 2022.06.22 | 
			  Comments