Replay transactions in Remix IDE
Don’t Repeat… Don’t Repeat— use the Transaction Recorder
With the “Transaction Recorder” you can:
- replay a sequence of transactions, you’ve run on Remix, send it to someone else for them to deploy using the same parameters as you.
- replay a sequence of transaction but with different parameters.
- test out a sequence of transactions on a testnet and then perform these transactions on the mainnet.
— all without a line of script.
Let’s start with a simple Storage contract :
pragma solidity >0.5.0 <0.6.0;contract Storage {
string public value;
constructor(string memory _value) public {
value = _value;
}
function setValue(string memory _value) public {
value = _value;
}
}
Compile the contract.
Open the Deploy & Run Transactions plugin :
- Deploy your contract with an initial value of dog. (Put the word dog in the box to the right of the Deploy button)
- Open up the deployed instance of the contract.
- Click the button named value
- You should see that dog has been input
- Now input bone into the the setValue function.
So far, so good. Now if you look closely above your “Deployed Contracts” you should have a section “Transaction recorded: 2”:
Whenever you create a sequence of transactions, Remix record them for you so you can replay them later.
View & Pure functions do not execute transactions so they are not saved by the recorder.
Expand the panel, hit the “save” icon, and give a name to your scenario:
Remix creates a new json file with your scenario.
TEST IT !
- Clear your dashboard (the trash icon to the right of “Deployed Contracts”).
- Make sure your .json file is the active tab in the editor.
- Click the Play button ( to the right of the floppy disk icon).
You should see the same sequence of transactions that you performed manually.
Let’s take a look at the simple-senario.json file:
- accounts: The list of accounts used during this scenario. You can change the account involved when you replay the transaction.
- linkReferences: References to external smart-contracts (very useful outside of the Javascript eVM).
- transactions: The list of transactions recorded (in our case 2).
- abis: The list of ABIs used for this scenario.
Now let’s focus of the first transaction :
parameters
: If you want test your scenario with different parameters just change them here. ⚠️Keep the order and type !abis & bytecode
: When deploying a contract, Remix puts the bytecode and abi inside the transaction record. You can share your scenario file with the world! Anyone can run it — as it. This is to say they can run it without the original solidity file .from
: Using the variableaccount{0}
gives you more control over the scenario (and is very useful when you switch from the JSVM to a testnet using MetaMask !).
There are many use cases for the Transactions Recorder
Share your code
The Transaction Recorder can be useful for getting help from a good samartan or for demonstration purposes in a class. You can walk them through a meaty sequence of transactions — either to:
- get them to a point where they need to start their work
- get them to a point where they can see your issue
Save Your Sanity
When you want to test out a complicated deployment of a series of contracts with specific parameters — and you want to adjust the parameters until you get it right.
In your own development process — by recording a series of transaction — you can save your work for later and don’t need to remember the sequence of transactions you performed.
Enjoy it and remember these lyrics:
Here we go yo, here we go yo
So what so what so what’s the scenario
Here we go yo, here we go yo
So what so what so what’s the scenario
-Senario by A Tribe Called Quest