定义umi的.mySigner签名标识符:`.use(signerIdentity(mySigner));`

huangapple go评论53阅读模式
英文:

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 &quot;@metaplex-foundation/umi-signer-wallet-adapters&quot;;
import { useWallet } from &quot;@solana/wallet-adapter-react&quot;;
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.

huangapple
  • 本文由 发表于 2023年6月8日 06:38:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427508.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定