Comments (4)
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.
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.
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.
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)
- Safe.global not working properly
- Gnosis Safe, dependency issues.
- Failed to fetch dynamically imported module: HOT 1
- WalletConnect: Has anyone had this error Failed to load wallet data: Operation timed out? HOT 9
- WalletConnect v2 support HOT 11
- Connection Stuck when new window or returning to website HOT 3
- Support for ethers@6 HOT 3
- vuedapp connect fails when used with nuxtlabs ui HOT 1
- Update WalletConnect dependencies HOT 3
- npm installation fails HOT 1
- ConnectError when connecting wallet using vue-dapp
- ConnectError when connecting wallet using vue-dapp HOT 1
- Error connecting to a phantom wallet HOT 3
- Pinia error when using in a composable HOT 3
- Hot reload is not working when import @vue-dapp/walletconnect HOT 1
- build runtime fail: resolutions for @noble/hashes HOT 1
- Wallet details not being completely removed on disconnect HOT 2
- fix: auto-connect attempt should be based on the last non-disconnected wallet's rdns
- Feat: Enable dapp browser HOT 1
- Don't auto-connect to MetaMask if it's locked HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-dapp.