Giter VIP home page Giter VIP logo

Comments (4)

zawilliams avatar zawilliams commented on August 21, 2024 1

Ah, duh *face palm*. I can't tell you how many times I've forgotten about .value with Vue 3 refs. Thanks for explaining all of that. Makes sense and got it working.

from vue-dapp.

johnson86tw avatar johnson86tw commented on August 21, 2024

Hello @zawilliams,

You can use useEthers to get signer which comes from ethers.js, and then you can create a contract by it.

(Notes: you should use useWallet to connect to wallet before using useEthers.)

vue-dapp useEthers docs: https://vue-dapp-docs.netlify.app/api/use-ethers.html
ethers.js Contract docs: https://docs.ethers.io/v5/api/contract/contract/#Contract-connect

const { signer } = useEthers()
const yourContract = new ethers.Contract(contractAddress, abi, signer);

This project is under development, so it's unstable. Welcome to contribute. In the future, it will have useMulticall for calling contracts in a more efficient way.

from vue-dapp.

zawilliams avatar zawilliams commented on August 21, 2024

Ah, that makes sense - I was assuming there was another abstraction having to do with contracts. After looking more through the code, that makes sense. Thanks for explaining. Would love to contribute - the simplicity of the package use is really nice.

So I tried using that code and when I'm using signer like that, it's giving me this error:

Uncaught Error: invalid signer or provider (argument="signerOrProvider", value={"_shallow":false,"__v_isRef":true,"_rawValue":null,"_value":null}, code=INVALID_ARGUMENT, version=contracts/5.4.1)

VSCode specifically is giving me:

Argument of type 'Ref<{ readonly provider?: { getNetwork: () => Promise<Network>; getBlockNumber: () => Promise<number>; getGasPrice: () => Promise<BigNumber>; getFeeData: () => Promise<...>; ... 24 more ...; readonly _isProvider: boolean; }; ... 16 more ...; _checkProvider: (operation?: string) => void; }>' is not assignable to parameter of type 'Signer | Provider'.
  Type 'Ref<{ readonly provider?: { getNetwork: () => Promise<Network>; getBlockNumber: () => Promise<number>; getGasPrice: () => Promise<BigNumber>; getFeeData: () => Promise<...>; ... 24 more ...; readonly _isProvider: boolean; }; ... 16 more ...; _checkProvider: (operation?: string) => void; }>' is missing the following properties from type 'Provider': getNetwork, getBlockNumber, getGasPrice, getFeeData, and 25 more.Vetur(2345)
const signer: Ref<{
    readonly provider?: {
        getNetwork: () => Promise<ethers.providers.Network>;
        getBlockNumber: () => Promise<number>;
        getGasPrice: () => Promise<ethers.BigNumber>;
        ... 25 more ...;
        readonly _isProvider: boolean;
    };
    ... 16 more ...;
    _checkProvider: (operation?: string) => void;
}>

I'm not as familiar with TypeScript, so I'm not sure if this is just TypeScript related.

Any thoughts?

from vue-dapp.

johnson86tw avatar johnson86tw commented on August 21, 2024

You should use signer.value because "signer" is wrapped by "ref".

const yourContract = new ethers.Contract(contractAddress, abi, signer.value);

But that will fail. Because the wallet has not yet connected, the signer.value is "null".
The temporary solution see below:

const { status, disconnect, error } = useWallet()
const { address, signer, setup } = useEthers()

watch(status, async (status) => {
  if (status === 'connected') {
    await setup()
    console.log(signer.value)
  }
})

I will add onConnected event handler in useEthers for a more convenient way to handle this situation.

from vue-dapp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.