简体   繁体   English

与智能合约erc721中的输入反应中的大数字相关的错误

[英]Error while related to big number in react for input in smart contract erc721

I want to integrate my smart contract with reactjs.我想将我的智能合约与 reactjs 集成。 I have this method called set_price() where i enter the value of token ID (in uint256) and price (uint256) .我有一个名为 set_price() 的方法,我在其中输入令牌 ID (in uint256) 和 price (uint256) 的值。 TokenID is basically a hash of some other values so it was of type byte32 and i have typecasted it into uint256. TokenID 基本上是一些其他值的哈希,所以它是 byte32 类型的,我已经将它类型转换为 uint256。 Now that when i enter the value from react it shows the following error:现在,当我从反应输入值时,它显示以下错误: 在此处输入图像描述

I have also added this line of code where I am trying to convert into big number我还在尝试转换为大数字的地方添加了这行代码在此处输入图像描述

and now i get this error:现在我得到这个错误: 在此处输入图像描述

I am also adding my file where I have instantiated web3.我还在实例化 web3 的位置添加我的文件。 The method that I am trying to solve is set_price.我试图解决的方法是 set_price。

 import Web3 from 'web3'; import TokenContract from './token.json'; let selectedAccount; let tokenid; let tokenContract; let isInitialized = false; export const init = async () => { let provider = window.ethereum; // if (typeof provider !== 'undefined') { //metamask is installed provider .request({ method: 'eth_requestAccounts' }) .then((accounts) => { selectedAccount = accounts[0]; console.log(`selected account is ${selectedAccount}`); }) .catch((err) => { console.log(err); return; }); window.ethereum.on('accountsChanged', function (accounts) { selectedAccount = accounts[0]; console.log(`Selected account changed to ${selectedAccount}`); }); } const web3 = new Web3(provider); tokenid = web3.utils.BN( 4116505640912284550723191986264393474293570820512791522119157812802259305428 ); const networkId = await web3.eth.net.getId(); tokenContract = new web3.eth.Contract( TokenContract.abi, TokenContract.networks[networkId].address ); isInitialized = true; }; export const itembyS = async () => { if (!isInitialized) { await init(); } // console.log(nftContract.methods.name.call()); return tokenContract.methods .itemBySupplier(4, 1, 1, 1) .send({ from: selectedAccount }); }; export const set_price = async () => { // var tokenid= BigNumber.from(4116505640912284550723191986264393474293570820512791522119157812802259305428); if (!isInitialized) { await init(); } // console.log(nftContract.methods.name.call()); return tokenContract.methods .itemForSale(tokenid, 200) .send({ from: selectedAccount }); }; export const showNum = async () => { if (!isInitialized) { await init(); } // const number = nftContract.methods.myFunction().call(); // console.log(number); return tokenContract.methods.enternum(1).send({ from: selectedAccount }); };

在此处输入图像描述

@tahlil is it loading now? @tahlil 现在正在加载吗? please let me know请告诉我在此处输入图像描述

The reason why we use big numbers is that JS can't directly handle big numbers...so you can't pass the "big number" as the whole number.我们之所以使用大数,是因为 JS 不能直接处理大数……所以不能把“大数”作为整数传递。 The BN object expects the big number as a string. BN 对象需要大数字作为字符串。 Like:喜欢:

tokenid =
    web3.utils.BN(
      "4116505640912284550723191986264393474293570820512791522119157812802259305428"
    );

That would solve the assertion error.这将解决断言错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 前端更好还是后端与智能合约(erc721)集成? - Is frontend better or backend for integration with smart contract (erc721)? 在 ERC721 上按所有者列出所有令牌 ID - list all token IDs by owner at ERC721 ERC 20 Token transferFrom 在我的智能合约中不起作用。 也不抛出任何异常 - ERC 20 Token transferFrom isn't working in my smart contract. Doesn't throw any Exception either 从 react-phone-number-input 导入电话号码验证器时出错 npm package - Getting an error while importing Phone number Validator from the react-phone-number-input npm package 如何从 React JS 访问智能合约功能? - How to access smart contract functions from React JS? 映射动态数组从智能合约起反应,其值包括地址和字符串 - map dynamic array in react from a smart contract with values an address and a string 智能合约:如何在 React 中获得 Solidity function 的回报? - Smart contract: How to get return of Solidity function in React? 建立React前端以实现以太稳固智能合约 - Building React front end for etherum solidity smart contract Solidity:从我的智能合约中显示价值以做出反应的问题 - Solidity : Problem to display value from my smart contract to react 通过前端反应表单创建和部署智能合约 - Creating and deploying a smart contract through a front end react form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM