lorisleiva / solana-twitter

Simple tweets as Solana accounts
202 stars 58 forks source link

Provider issue #12

Open Harold-coder opened 2 years ago

Harold-coder commented 2 years ago

When I try to run the code after episode 9, I get this error:

_project_serum_anchor__WEBPACK_IMPORTED_MODULE_3__.Provider is not a constructor at ReactiveEffect.eval [as fn] (useWorkspace.js?a7cf:15:1)

Here is my useWorkspace.js

import { computed } from 'vue'
import { useAnchorWallet } from 'solana-wallets-vue'
import { Connection, PublicKey } from '@solana/web3.js'
import { Provider, Program } from '@project-serum/anchor'
import idl from '../../../target/idl/solana_twitter.json'

const programID = new PublicKey(idl.metadata.address)
let workspace = null

export const useWorkspace = () => workspace

export const initWorkspace = () => {
    const wallet = useAnchorWallet()
    const connection = new Connection('http://127.0.0.1:8899')
    const provider = computed(() => new Provider(connection, wallet.value))
    const program = computed(() => new Program(idl, programID, provider.value))

    workspace = {
        wallet,
        connection,
        provider,
        program,
    }
}
enyelsequeira commented 2 years ago

if you are having this issue, update @project-serum/achor. this is always changing so this might be the cause of your issue the version I am using is "@project-serum/anchor": "^0.21.0", and this works fine