Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update "EVM Token Transfers" Documentation for SDK V3 #170

Open
saadahmsiddiqui opened this issue Oct 7, 2024 · 0 comments
Open

Update "EVM Token Transfers" Documentation for SDK V3 #170

saadahmsiddiqui opened this issue Oct 7, 2024 · 0 comments

Comments

@saadahmsiddiqui
Copy link
Member

saadahmsiddiqui commented Oct 7, 2024

The title of the page should be renamed to "EVM Fungible Token Transfers"

Update the page with following content:

Transferring a fungible asset between EVM chains

Transferring assets between EVM-based chains can be achieved using the Sygma SDK. To facilitate the transfer, the following steps are required:

  1. Specify transfer parameters such as amount, recipient address, token, destination chain and use the method createFungibleAssetTransfer from @buildwithsygma/evm to create an instance of FungibleAssetTransfer
  2. Check for any approvals required, and if required sign and broadcast these transactions.
  3. Prepare, sign, and send the Transfer transaction to the Source network node

1. Create and initialize the transfer object

To initialize the asset transfer object, the following parameters are required:

  • An EIP1193 compatible EVM provider
  • Environment variable SYGMA_ENV needs to be set as mainnet or testnet
const fungibleTokenTransfer = await createFungibleAssetTransfer({
  source: 1, // Ethereum Mainnet
  destination: 8453, // Base
  sourceNetworkProvider: eip1193CompatibleProvider,
  resource: "0x0000000000000000000000000000000000000000000000000000000000000002", // ETH Resource ID can be found here: https://github.com/sygmaprotocol/sygma-shared-configuration/blob/0e3470df4935ae3cce8b44f496723070ff3b3d1c/mainnet/shared-config-mainnet.json
  amount: BigInt(1) * BigInt(1e17),
  recipientAddress: "",
  sourceAddress: sourceAddress, // source wallet address
});

2. Send Approval transactions

You can check if approvals are required for your transfer. If there are approvals required for the transfer, you can sign the transaction and send it.

const approvals = await fungibleTokenTransfer.getApprovalTransactions();
for (const approval of approvals) {
  const tx = await wallet.sendTransaction(approval);
  await tx.wait();
}

3. Send transfer transaction

Once all the approvals have been confirmed you can finally send the actual fungible token transfer transaction.

const transfer = await transfer.getTransferTransaction();
const tx = await wallet.sendTransaction(transfer);
await tx.wait();

Checking transaction hash

The response object returned by the sendTransaction method contains a hash property. This transaction hash is logged to the console, and it can be used to look up the transaction on a block explorer.

console.log("Sent transfer with hash: ", tx.hash);

A full example of the above can be found here

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

No branches or pull requests

1 participant