solana-twitter icon indicating copy to clipboard operation
solana-twitter copied to clipboard

Provider issue

Open Harold-coder opened this issue 2 years ago • 1 comments

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,
    }
}

Harold-coder avatar Jun 23 '22 11:06 Harold-coder

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

enyelsequeira avatar Jun 29 '22 16:06 enyelsequeira