-
-
Save cmdzro/0547725ca6faa2067e7edf3c70b697f1 to your computer and use it in GitHub Desktop.
Send erc20 token transfer transaction to gnosis safe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.