I'm, trying to connect a front-end to my smart contract but whenever I call the function from the UI I get this error:
Uncaught (in promise) Error:
Provided address [object Promise] is invalid, the capitalization checksum test failed, or it's an indirect IBAN address which can't be converted.
I'm completely lost. I guess this has something to do with the contract address but I'm not sure what I did wrong. Other answers regarding this error didn't help me. Here is the code:
<script type="text/javascript">
var abi = contractAbi;
var address = "0x773e94b3394913FD7D1562ADf21A2D8e0720c38F";
async function loadWeb3() {
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
window.ethereum.enable();
}
}
async function loadContract(){
return await new window.web3.eth.Contract(abi,address);
}
async function load() {
await loadWeb3();
window.contract = await loadContract();
}
async function getCurrentAccount() {
const accounts = await window.web3.eth.getAccounts();
return accounts[0];
}
async function listNFT(){
var buyerAddress = document.getElementById('buyer-address').value;
var tokenId = document.getElementById('sell-tokenId').value;
var price = document.getElementById('selling-price').value;
const account = getCurrentAccount();
await window.contract.methods.listNFT(buyerAddress,price,tokenId).send({from: account, value:100000});
}
async function buy(){
var sellerAddress = document.getElementById('seller-address').value;
var tokenId = document.getElementById('tokenId').value;
var price = document.getElementById('price').value;
const account = await getCurrentAccount();
await window.contract.methods.buy(sellerAddress,tokenId,price).send({from: account});
}
load();
</script>
Any tips ?