0


I'm trying to recreate this site TenThousandSu
And this is the smart contract I'm trying to call https://rinkeby.etherscan.io/address/0x7e338acfb7a5d7e99f4225cc12dc884f49c00f6a#code
I'm using "1.0.0-beta.35" version of web3js.

I'm having difficulties connecting to a users wallet and executing a smart contract on their wallet. If you go to tenthousandsu.com and click the Buy button you'll first get a prompt asking you if the smart contract can connect to your wallet. After you accept that, it asks you if you want to let the smart contract execute a transacation. To clarify look at the below pictures.

Connecting to wallet Executing smart contract on the wallet
I'm neither sure how to make picture 1 or picture 2 happen. I have never been able to do that from my program. I'm just trying to call the function purchase(uint256 _nftId) on line 721 in the smart contract I've made on rinkeby. The code below is what I've tried.

contract.methods.purchase(squareNumber);

The code above in my mind should execute what is displayed on the 2nd picture. But I would prefer if I could do something like this

contract.methods.purchase(squareNumber, (err, res) => {
          console.log([err, res]);
          if (!err) {
            // HANDLE SUCCESS
          } else {
            alert(err);
          }
        });

And for the 1st picture I'm not even sure what to do. I'm not sure how to prompt the user to accept a "Connect Request".

4
  • First try upgrading to web3 v1.2. Without the code to test there's not much we can tell you about. From your captures the error message says the account do not have enough funds.
    – Ismael
    Sep 1, 2019 at 21:23
  • I've read my post again and I can see how you couldn't understand what my question is. I've edited the post now with more details of my issue. I hope it's clear now what I don't understand. I'll clarify further and provide the full code to my project if there's still some uncertainty left.
    – RazerBoy
    Sep 2, 2019 at 20:59
  • And if I change the web3js version to 1.2 or 1.2.1 I get this two errors web3.min.js:1 Uncaught ReferenceError: regeneratorRuntime is not defined and Uncaught (in promise) ReferenceError: Web3 is not defined. I just change web3.js to [email protected] in this line <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
    – RazerBoy
    Sep 2, 2019 at 21:11
  • MetaMask has a very good documentation you should start there metamask.github.io/metamask-docs/Main_Concepts/Getting_Started. For example for the first picture you should execute ethereum.enable().
    – Ismael
    Sep 2, 2019 at 21:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.