Skip to content

Instantly share code, notes, and snippets.

@yann300
Created May 12, 2025 16:26
Show Gist options
  • Select an option

  • Save yann300/bba56b08b316f4727e24d2f4703bc7fc to your computer and use it in GitHub Desktop.

Select an option

Save yann300/bba56b08b316f4727e24d2f4703bc7fc to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.30+commit.73712a01.js&optimize=false&runs=200&gist=
import { deploy } from './ethers-lib'
(async () => {
try {
const accountWithToken = '0x5B38Da6a701c568545dCfcB03FcB875f56beddC4'
const accountNullBalance = '0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2'
let erc20 = await deploy('MyToken', ['0x5B38Da6a701c568545dCfcB03FcB875f56beddC4'])
console.log(`MyToken address: ${erc20.address}`)
const sender = await deploy('Sender', [erc20.address])
console.log(`Sender address: ${sender.address}`)
// mint 1000000 token to 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
await (await erc20.mint(accountWithToken, 1000000))
// check
console.log('balance', (await erc20.balanceOf(accountWithToken)).toString())
// encode call 1 : Approve Sender to spend 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 balance (1000000)
const data1 = erc20.interface.encodeFunctionData('approve', [sender.address, 1000000])
// encode call 2 : Use Sender to send 100000 token to 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 from 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 balance
const data2 = sender.interface.encodeFunctionData('send', [accountWithToken, accountNullBalance, 10000])
const executeBatch = [
[erc20.address, 0, data1],
[sender.address, 0, data2]
]
console.log(executeBatch)
console.log(JSON.stringify(executeBatch))
// [["0xa3A518Ba4e193Fb129aa379F5916d4660f15cE5D",0,"0x095ea7b3000000000000000000000000df9d0c45d97f134151a386e0aa23b09ca903c13f00000000000000000000000000000000000000000000000000000000000f4240"],["0xDf9D0C45d97f134151a386E0AA23b09CA903c13f",0,"0x0779afe60000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb20000000000000000000000000000000000000000000000000000000000002710"]]
} catch (e) {
console.log(e.message)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment