solana-solanaj SDK无法创建账户问题

我在学习使用solana官方推荐的java SDK solanaj进行开发 碰到了如下问题:

Maven:

<dependency>
    <groupId>com.mmorrell</groupId>
    <artifactId>solanaj</artifactId>
    <version>1.19.2</version>
</dependency>
@Test
void testCreateAccount() throws Exception {
    OkHttpClient customHttpClient = new OkHttpClient.Builder()
            .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 7890))) 
            .readTimeout(20, TimeUnit.SECONDS)
            .build();

    RpcClient client = new RpcClient(Cluster.DEVNET.getEndpoint(),customHttpClient);

    Account payer = getAccount();
    System.out.println("payer: " + payer.getPublicKey());

    Account mintKeypair = new Account();
    PublicKey mintPubkey = mintKeypair.getPublicKey();

    // 82
    Object value = SolCommonEnum.MINT_SIZE.getValue();
    Long space = Long.valueOf(value.toString());
    long lamports = getLamports(client, space);
    System.out.println("lamports value: " + lamports);

    // create mint
    TransactionInstruction createMintAccountInstruction = SystemProgram.createAccount(
            payer.getPublicKey(),
            mintPubkey,
            lamports,
            space,
            PublicKey.valueOf("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
    );

    // init mint
    TransactionInstruction initializeMintInstruction = TokenProgram.initializeMint(
            mintPubkey,
            2,
            payer.getPublicKey(),
            payer.getPublicKey()
    );

    Transaction transaction = new Transaction();

    String recentBlockHash = getRecentBlockHash(client);

    ArrayList<Account> accounts = new ArrayList<>();
    accounts.add(payer);
    accounts.add(mintKeypair);

    // add
    transaction.addInstruction(createMintAccountInstruction);
    transaction.addInstruction(initializeMintInstruction);

    String res = client.gatApi().sendTransaction(transaction, accounts, recentBlockHash, new RpcSendTransactionConfig());

    System.out.println("Transaction Signature: " +res);
}

如果像上述写法,进行执行,会得到交易的base64地址,但是去solana的开发环境进行查询未查询到对应操作。 于是我将"sendTransaction"方法中的base64码拿出借用其中的call方法使用method值替换为simulateTransaction,得到的返回结果尽然是:

{
  "jsonrpc" : "2.0",
  "result" : {
    "context" : {
      "apiVersion" : "2.0.13",
      "slot" : 333797603
    },
    "value" : {
      "accounts" : null,
      "err" : {
        "InstructionError" : [ 0, "MissingRequiredSignature" ]
      },
      "innerInstructions" : null,
      "logs" : [ "Program 11111111111111111111111111111111 invoke [1]", "Allocate: 'to' account Address { address: 4ciycXCoFo5SveW8jGsks5TKqGs7ProV8ut21V6U6Unw, base: None } must sign", "Program 11111111111111111111111111111111 failed: missing required signature for instruction" ],
      "replacementBlockhash" : null,
      "returnData" : null,
      "unitsConsumed" : 150
    }
  },
  "id" : "afb5c3d5-2dde-4ba9-86d9-89db774f5949"
}

错误信息表明在执行Solana的指令时缺少必要的签名。可我上述测试用例中名且添加了我的两个账户到List中。不知道为什么

请先 登录 后评论

2 个回答

jc0803kevin - 合约开发/区块链开发/项目管理
请先 登录 后评论
✨ 轻盈✨
请先 登录 后评论
  • 2 关注
  • 0 收藏,343 浏览
  • jxGold 提出于 2024-10-18 22:09