coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.69k stars 1.35k forks source link

TypeError: provider.send is not a function #2846

Closed emaborsa closed 8 months ago

emaborsa commented 8 months ago

I must confess I am new in web3 but quite familiar with Typescript. I have the following snippet:

  async function createMint(provider: anchor.Provider, authority: PublicKey) {
    if (authority === undefined) {
      authority = provider.publicKey;
    }
    const mint = anchor.web3.Keypair.generate();
    const instructions = await createMintInstructions(provider, authority, mint.publicKey);

    const tx = new anchor.web3.Transaction();
    tx.add(...instructions);

    await provider.send(tx, [mint]);

    return mint.publicKey;
  }

At runtime I get TypeError: provider.send is not a function. Moving to sendAndConfirm works. Is the type definition wrong or am I missing something?

My package.json:

{
    "scripts": {
        "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
        "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
    },
    "dependencies": {
        "@coral-xyz/anchor": "^0.29.0",
        "@project-serum/anchor": "^0.26.0",
        "@project-serum/common": "^0.0.1-beta.3",
        "@project-serum/serum": "^0.13.65"
    },
    "devDependencies": {
        "@types/bn.js": "^5.1.0",
        "@types/chai": "^4.3.0",
        "@types/mocha": "^9.0.0",
        "chai": "^4.3.4",
        "mocha": "^9.0.3",
        "prettier": "^2.6.2",
        "ts-mocha": "^10.0.0",
        "typescript": "^4.3.5"
    }
}
acheroncrypto commented 8 months ago

send method of the Provider interface is optional.

https://github.com/coral-xyz/anchor/blob/ddcb3b826042891b6e2167e0d1559d8d053086c8/ts/packages/anchor/src/provider.ts#L26-L30

You can use AnchorProvider instead of provider which has the required types for sendAndConfirm.

Also, I'd remove "@project-serum/anchor": "^0.26.0", dependency entry as that package is deprecated.