Skip to content

Conversation

@npty
Copy link
Member

@npty npty commented Mar 26, 2025

Description

Added typeScript bindings for axelar-cgp-sui smart contracts.

Code Generation

The following command will generate the typescript code for the contracts on devnet-amplifier, testnet, and mainnet envs. It will fetches the ABIs from the fullnode using the contract addresses and generate the typescript code. The contract addresses is fetched from the s3 file.

pnpm codegen

As a result, the typescript code will be generated in the src directory as follows:

src
├╴ devnet-amplifier
│ ├╴ abis
│ │ ├╴ 0xabcd...0123.json
│ │ ├╴ 0xabcd...0123.json
│ │ └╴ index.ts
│ └╴ types
│   ├╴ 0xabcd...0123.ts
│   ├╴ 0xabcd...0123.ts
│   └╴ index.ts
├╴ mainnet
│ ├╴ abis
│ │ ├╴ 0xabcd...0123.json
│ │ ├╴ 0xabcd...0123.json
│ │ └╴ index.ts
│ └╴ types
│   ├╴ 0xabcd...0123.ts
│   ├╴ 0xabcd...0123.ts
│   └╴ index.ts
├╴ testnet
│ ├╴ abis
│ │ ├╴ 0xabcd...0123.json
│ │ ├╴ 0xabcd...0123.json
│ │ └╴ index.ts
│ └╴ types
│   ├╴ 0xabcd...0123.ts
│   ├╴ 0xabcd...0123.ts
│   └╴ index.ts

Usage

This is how it could be used to send ITS Interchain Transfer. Full source code is available here.

// Create a new transaction block
  const tx = new Transaction();

  // Split Gas for paying axelar fee
  const gas = tx.splitCoins(tx.gas, [BigInt(fee)]);

  // Split Coin for transferring amount through interchain transfer
  const transferCoin = tx.splitCoins(tx.object(itsCoinObjectId), [UNIT_AMOUNT]);

  // Create a new channel
  const channel = AxelarGateway.channel.builder.new$(tx, []);
  const tokenId = InterchainTokenService.token_id.builder.fromU256(tx, [
    BigInt(ITS_TOKEN_ID),
  ]);

  // Prepare interchain transfer
  const ticket =
    InterchainTokenService.interchain_token_service.builder.prepareInterchainTransfer(
      tx,
      [
        tokenId,
        transferCoin,
        DESTINATION_CHAIN,
        tx.object(DESTINATION_ADDRESS),
        tx.object("0x"),
        channel,
      ],
      [ITS_TOKEN_TYPE],
    );

  // Send interchain transfer
  const messageTicket =
    InterchainTokenService.interchain_token_service.builder.sendInterchainTransfer(
      tx,
      [objectIds.its, ticket, CLOCK_PACKAGE_ID],
      [ITS_TOKEN_TYPE],
    );

  // Pay gas for the transfer
  GasService.gas_service.builder.payGas(
    tx,
    [objectIds.gasService, messageTicket, gas, walletAddress, tx.object("0x")],
    ["0x2::sui::SUI"],
  );

  // Send the message
  AxelarGateway.gateway.builder.sendMessage(tx, [
    objectIds.gateway,
    messageTicket,
  ]);

  // Destroy the channel
  AxelarGateway.channel.builder.destroy(tx, [channel]);

  // Sign and execute the transaction
  const response = await suiClient.signAndExecuteTransaction({
    transaction: tx,
    signer: suiWallet,
    options: {
      showEffects: true,
      showObjectChanges: true,
    },
  });

@vercel
Copy link

vercel bot commented Mar 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
axelar-maestro ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 31, 2025 11:38am
axelar-registry ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 31, 2025 11:38am
axelar-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 31, 2025 11:38am
axelarjs-maestro-devnet-amplifier ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 31, 2025 11:38am

@changeset-bot
Copy link

changeset-bot bot commented Mar 26, 2025

🦋 Changeset detected

Latest commit: a5d0599

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@axelarjs/sui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant