I want to integrate my smart contract with reactjs. I have this method called set_price() where i enter the value of token ID (in uint256) and price (uint256) . TokenID is basically a hash of some other values so it was of type byte32 and i have typecasted it into 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
I am also adding my file where I have instantiated web3. The method that I am trying to solve is 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 });
};