Created
January 19, 2022 10:03
-
-
Save drgorillamd/cdf9a480ce8123eca5e46dceecc9c412 to your computer and use it in GitHub Desktop.
Craft tx
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
const ethers = require('ethers'); | |
const { Interface } = require('ethers/lib/utils'); | |
const contractAddress = ''; | |
const key = ''; | |
const RPC_SERVER = ''; | |
async function main () { | |
try { | |
const provider = new ethers.providers.JsonRpcProvider(RPC_SERVER); | |
const signer = new ethers.Wallet(key, provider); | |
const EXTRA_ADDRESS = ethers.Wallet.createRandom(); | |
// function myFn(uint256 _amount) external | |
let iface = new Interface(['function myFn(uint256)']); | |
let inputData = ethers.utils.defaultAbiCoder.encode(["uint256","address"],[1, EXTRA_ADDRESS.address]); | |
inputData = iface.getSighash('myFn')+inputData.slice(2); | |
const txParams = { | |
to: contractAddress, | |
data: inputData, | |
}; | |
let tx = await signer.sendTransaction(txParams); | |
await tx.wait() | |
} catch (e) { | |
console.log(e); | |
} | |
} | |
main(); | |
process.on('exit', function(code) { | |
return console.log(`Exit with code ${code}`); | |
}); | |
process.on('SIGINT', _ => { | |
process.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment