英文:
How to define mySigner for umi's .use(signerIdentity(mySigner));
问题
I'm creating a n umi instance and can't find info on how to define the mySigner const to use in creating the instance. Here's what I got.
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { mplCandyMachine } from "@metaplex-foundation/mpl-candy-machine";
import { publicKey, signerIdentity, KeypairSigner } from "@metaplex-foundation/umi";
const mySigner = ???;
// Use the RPC endpoint of your choice.
export const umi = createUmi(endpoint)
.use(signerIdentity(mySigner))
.use(mplCandyMachine());
thank you, in advanced.
英文:
I'm creating a n umi instance and can't find info on how to define the mySigner const to use in creating the instance. Here's what I got.
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { mplCandyMachine } from "@metaplex-foundation/mpl-candy-machine";
import { publicKey, signerIdentity, KeypairSigner } from "@metaplex-foundation/umi";
const mySigner = ???;
// Use the RPC endpoint of your choice.
export const umi = createUmi(endpoint)
.use(signerIdentity(mySigner))
.use(mplCandyMachine());
thank you, in advanced.
</details>
# 答案1
**得分**: 0
这取决于您想要使用什么。有不同的选项:
这将生成一个新的密钥对:
```javascript
const mySigner = generateSigner(umi);
umi.use(keypairIdentity(myKeypairSigner))
您也可以像这样导入一个密钥对:
const myKeypair = umi.eddsa.createKeypairFromSecretKey(mySecretKey);
const myKeypairSigner = createSignerFromKeypair(myKeypair);
umi.use(keypairIdentity(myKeypairSigner));
如果您想要使用钱包(如phantom、backback、Solflare),您应该使用普通的钱包适配器:
import { walletAdapterIdentity } from "@metaplex-foundation/umi-signer-wallet-adapters";
import { useWallet } from "@solana/wallet-adapter-react";
const wallet = useWallet();
umi.use(walletAdapterIdentity(wallet))
而这将创建一个基于公钥的虚拟签名器。(注意:它实际上不能签名,只是一个辅助工具)
const mySigner = createNoopSigner(myPublicKey);
您可以在umi readme中找到有关签名器主题的更多信息。
英文:
It depends on what you want to use. There are different options:
This results in a newly generated keypair:
const mySigner = generateSigner(umi);
umi.use(keypairIdentity(myKeypairSigner))
you can also import a keypair like this:
const myKeypair = umi.eddsa.createKeypairFromSecretKey(mySecretKey);
const myKeypairSigner = createSignerFromKeypair(myKeypair);
umi.use(keypairIdentity(myKeypairSigner));
If you want to use a wallet (like phantom, backback, Solflare) you should use the normal wallet adapter:
import { walletAdapterIdentity } from "@metaplex-foundation/umi-signer-wallet-adapters";
import { useWallet } from "@solana/wallet-adapter-react";
const wallet = useWallet();
umi.use(walletAdapterIdentity(wallet))
while this creates a dummy Signer based on a public key. (Attention: it can not actually sign but is only a helper
const mySigner = createNoopSigner(myPublicKey);
You can find more info on the signer topic in the umi readme.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论