现在我要连接 solana 和 React.js。 我试图得到这样的钱包。
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
....
function Header(props) {
const wallet = useWallet();
const initialize = async () => {
const provider = await getProvider()
const program = new Program(contractJson, programID, provider);
console.log('program', program)
try {
/* interact with the program via rpc */
await program.rpc.initialize({
accounts: {
myOntology: provider.wallet.publicKey,
user: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
},
});
} catch (err) {
console.log("Transaction error: ", err);
}
}
}
当我调用初始化方法时,出现此错误。 类型错误:this.wallet.signTransaction 不是函数 所以我已经记录了钱包并且signTransaction 为空。 enter image description here
如何解决这个问题?
最佳答案
您加入计划的提供商需要合并您的钱包
const wallet = useWallet();
const connection = new Connection('<devnet url here>')
const provider = new anchor.Provider(connection, wallet, anchor.Provider.defaultOptions())
const program = new Program(contractJson, programID, provider);
关于reactjs - Solana React TypeError : this. wallet.signTransaction 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69280753/