Gnosis Safe – How to Send ERC20 & ERC721 Tokens Using Safe Core SDK

gnosisgnosis-safesafe-core-sdk

I am using Safe Core SDK in my web app(Next.js) project to generate and deploy Safes on Polygon Testnet(Mumbai) by the users. I can see the functions provided by SDK to create, sign and execute transactions for Ether/Matic transfer but am not able to understand how to send ERC20 and ERC721 tokens. Can someone please guide how to do this?

Best Answer

To create a token transfer you need to execute the following code:

import { SafeTransactionDataPartial } from '@gnosis.pm/safe-core-sdk-types'

const transaction: SafeTransactionDataPartial = {
  to: '<TOKEN_CONTRACT_ADDRESS>',
  value: '0',
  data: '<DATA>'
}
const safeTransaction = await safeSdk.createTransaction(transaction)

where TOKEN_CONTRACT_ADDRESS is the address of the token contract and DATA is the encoding of the call to the transfer method: contractInstance.methods.transfer(toAddress, amount).encodeABI()

Related Topic