Skip to content

Instantly share code, notes, and snippets.

@cmdzro
Last active November 9, 2021 13:36
Show Gist options
  • Save cmdzro/0547725ca6faa2067e7edf3c70b697f1 to your computer and use it in GitHub Desktop.
Save cmdzro/0547725ca6faa2067e7edf3c70b697f1 to your computer and use it in GitHub Desktop.
Send erc20 token transfer transaction to gnosis safe
import { run, ethers } from "hardhat"
import Safe, { SafeTransactionOptionalProps } from "@gnosis.pm/safe-core-sdk"
import { EthersAdapter } from "@gnosis.pm/safe-core-sdk"
import { MetaTransactionData } from '@gnosis.pm/safe-core-sdk-types'
const safeAddress = "0xfA64EE..." // on rinkeby testnet
const tokenAddress = "0x18B225..." // on rinkeby testnet
const TokenFactory = await ethers.getContractFactory("TokenContract")
const token = TokenFactory.attach(tokenAddress)
const [owner] = await ethers.getSigners()
const ethAdapter = new EthersAdapter({
ethers,
signer: owner
})
const safeSdk = await Safe.create({ ethAdapter, safeAddress })
const safe = await safeSdk.connect({ ethAdapter, safeAddress })
const unsignedTransaction = await token.populateTransaction.transfer("0x5d07C6...", 100)
console.log(unsignedTransaction)
const transactions: MetaTransactionData[] = [{
to: tokenAddress,
value: "0",
data: unsignedTransaction.data!
}]
const safeTransaction = await safe.createTransaction(transactions)
console.log(safeTransaction) // returns with a different "to" than specified in line 27
const owner1Signature = await safe.signTransaction(safeTransaction)
console.log(`owner signature: ${owner1Signature}`) // returns undefined
@cmdzro
Copy link
Author

cmdzro commented Nov 9, 2021

Thx a lot for your help @germartinez , greatly appreciated 🤗 ... I'll read up on all this and get back if I have further questions.

You are all very supportive ❤️ – Thx again!

@cmdzro
Copy link
Author

cmdzro commented Nov 9, 2021

Quick update: I got it to work 🎉 thx @germartinez @rmeissner and @DmitryBespalov!

I'll try to write something up to have others also benefitting from my learnings.

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