Untitled

mail@pastecode.io avatar
unknown
javascript
a month ago
2.0 kB
4
Indexable
Never
import { TransactionBlock } from "@mysten/sui.js/transactions";
import { bcs } from "@mysten/sui.js/bcs";
import { SuiClient, getFullnodeUrl } from "@mysten/sui.js/client";
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
import { fromB64, toHEX } from "@mysten/sui.js/utils";

const pkg =
  "0x31ec1704ae942cfd22c3e9e9809fe26f78458d1b71f6339b17d5fedfebbfae8a";
const client = new SuiClient({ url: getFullnodeUrl("testnet") });
const getKeypair = (secret: string): Ed25519Keypair => {
  // check if we have a mnemonic
  if (secret.includes(" ")) {
    return Ed25519Keypair.deriveKeypairFromSeed(secret);
  } else {
    const privkey: number[] = Array.from(fromB64(secret));
    privkey.shift(); // this will be needed to form a signature
    const privateKey = Uint8Array.from(privkey);
    return Ed25519Keypair.fromSecretKey(privateKey);
  }
};

const proveManos = async () => {
  const charityBCS = bcs.struct("Charity", {
    name: bcs.u8(),
    details: bcs.u8(),
  });

  const charities = [
    {
      name: 5,
      details: 6,
    },
  ];

  const tx = new TransactionBlock();
  tx.setSender(
    "0x6f2d5e80dd21cb2c87c80b227d662642c688090dc81adbd9c4ae1fe889dfaf71"
  );
//   tx.moveCall({
//     target: `${pkg}::charity::test2`,
//     arguments: [tx.pure(charityBCS.serialize({ name: 5, details: 6 }).toBytes())],
//   });

  const charity = charityBCS.serialize({ name: 5, details: 6 }).toBytes();
    console.log(charity,toHEX(charity));
    tx.moveCall({
        target: `${pkg}::charity::test2`,
        arguments: [tx.pure(charity)],
    });

  const bytes = await tx.build({ client});
//   console.log(bytes);

  // const response = await client.signAndExecuteTransactionBlock({
  //     transactionBlock: tx,
  //     signer: getKeypair("ACGrHNXjXYqasmhChBDTvItmj6eDFhBNVwF1cYiGsTmA"),
  //     options: {
  //         showEffects: true
  //     }
  // });
  // console.log(JSON.stringify(response));
};

proveManos();
Leave a Comment