3

Getting an error publicKey.toBase58 is not a function when calling delegateStaingV1

I've spent quite some time making sure my UMI instance is setup correctly to use the walletAdapterIdentity plugin and createSignerFromWalletAdapter, but i believe my error may lie within this somewhere (perhaps the way im stating the signer.

Should i be using umi.use(signerIdentity(createSignerFromWalletAdapter(umi, wallet))); or should the UMI instance be configured solely with createUmi?

I was following the docs at: https://github.com/metaplex-foundation/umi/tree/main/docs https://developers.metaplex.com/token-metadata/delegates#staking-delegate-pnft-only

Here is a snippet of my code base (VueJs):

const connection = new Connection(endpoint)
const wallet = useWallet()

const umi = createUmi(connection)
    .use(walletAdapterIdentity(wallet))
    .use(mplTokenMetadata())

const signer = createSignerFromWalletAdapter(wallet);
umi.identity = signer
umi.payer = signer
umi.use(signerIdentity(createSignerFromWalletAdapter(umi, wallet)));

const stakingDelegate = new PublicKey('publicKeyPlaceholder');
const mint = new PublicKey('publicKeyPlaceholder');

const delegate = async () => {
    try {
        await delegateStakingV1(umi, {
            mint,
            tokenOwner: signer.publicKey,
            authority: signer,
            authorizationRules: new PublicKey('eBJLFYPxJmMGKuFwpDWkzxZeUrad92kZRC5BJLpzyT9'),
            delegate: stakingDelegate,
            tokenStandard: TokenStandard.ProgrammableNonFungible,
        }).sendAndConfirm(umi)

    } catch (error) {
        console.error('Error delegating:', error);
    }
}

Update:

When i change my signer from:

const signer = createSignerFromWalletAdapter(umi, wallet);

to:

const signer = createSignerFromWalletAdapter(wallet);

The error I'm receiving becomes a wallet adapter issue:

enter image description here

1 Answer 1

1

You are using the PublicKey class from legacy web3.js as opposed to the PublicKey type that Umi expects — i.e. a simple base58 string opaque type.

You need to replace things like:

const stakingDelegate = new PublicKey('publicKeyPlaceholder');
const mint = new PublicKey('publicKeyPlaceholder');

to:

import { publicKey } from "@metaplex-foundation/umi";

const stakingDelegate = publicKey('publicKeyPlaceholder');
const mint = publicKey('publicKeyPlaceholder');

See Umi's documentation regarding PublicKeys here.

There's also a helper package to help you convert to and from legacy web3.js classes if you had to convert a PublicKey class into a PublicKey type from Umi:

import { fromWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";

const stakingDelegate = fromWeb3JsPublicKey(stakingDelegateFromWeb3Js);
const mint = fromWeb3JsPublicKey(mintFromWeb3Js);

See Umi's documentation regarding Web3.js adapters here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.