Reputation: 9
I'm trying to call a mint function from js using web3.js and I get unknown account.
this is my smart contract function
function assign(string calldata tokenURI, bytes calldata bytesId) public {
uint256 _tokenId = abi.decode(bytesId, (uint256));
_mint(msg.sender, _tokenId);
_setTokenURI(_tokenId, tokenURI);
emit Assigned(_tokenId, msg.sender, bytesId);
}
This is my js code
Contract.setProvider("https://rpc.ankr.com/polygon_mumbai");
const contract = new Contract(CONTRACT_NFT_ABI, CONTRACT_NFT_ADDRESS);
await contract.methods.assign(tokenURI, plotID)
.send({from: userAddress}, function(error, transactionHash){
if (transactionHash){
res.status(200).send({
res: "OK",
msg: transactionHash
});
}
if (error) {
res.status(200).send({
res: "KO",
msg: error
});
}
});
Everyone can mint. I use Metamask to get address.
Anyone can help me??
Thanks
Upvotes: 0
Views: 445
Reputation: 49
This is quite common as this is a small issue with carring the same connected provider to the approval instance,
here is the fix,
let provider;
await web3Modal
.connect(web3Modal)
.then((res) => {
provider = res;
})
.catch((err) => {
console.error(err)
});
the response provider is then used for connecting or for performing the actions of every transaction linked with the same account.
const web3 = new Web3(provider);
will be the final solution,
Contract.setProvider(provider);
would be the solution for this issue.
Upvotes: 0