Skip to content

Instantly share code, notes, and snippets.

View mariano-aguero's full-sized avatar
:octocat:
Focusing

Mariano Aguero mariano-aguero

:octocat:
Focusing
View GitHub Profile

0x2bfa3a690b88f51c03ddf63e16d9ce55818ca417e6f52adb4b0ab326572bb9e3

@mariano-aguero
mariano-aguero / revert.ts
Created September 30, 2020 17:01 — forked from spalladino/revert.ts
Get the revert reason before sending an Ethereum transaction if the transaction would fail
export async function tryGetRevertReason(to: string, from: string, data: string): Promise<string | undefined> {
const provider = ethers.getDefaultProvider();
const tx = { to, from, data };
try {
await provider.estimateGas(tx);
} catch {
const value = await provider.call(tx);
return hexDataLength(value) % 32 === 4 && hexDataSlice(value, 0, 4) === '0x08c379a0'
? defaultAbiCoder.decode(['string'], hexDataSlice(value, 4))
: undefined;
@mariano-aguero
mariano-aguero / sender.ligo
Created June 16, 2020 13:57
Sender example
type request is record
callback : contract(int)
end
type action is
| GetBar of (request)
| SetBar of (int)
type store is record
bar: int;
@mariano-aguero
mariano-aguero / inspector.ligo
Created June 16, 2020 13:56
Inspector example
type action is
| GetFoo of (address)
| SetFoo of (int)
type store is record
foo: int;
end
type return is list (operation) * store
@mariano-aguero
mariano-aguero / counter.ligo
Created June 16, 2020 13:54
Counter example
type action is
| Increment of (int)
| Decrement of (int)
| Reset of (unit)
type store is int
type return is list (operation) * store
const emptyOps: list(operation) = list end
@mariano-aguero
mariano-aguero / proxy.ligo
Created June 16, 2020 13:53
Proxy example
type action is
| Increment of (int)
| Decrement of (int)
| Reset of (unit)
type store is unit
type return is list (operation) * store
const dest : address = ("KT1ExEhdgHTzotFdPsp4mhNC6rqK4h6EKUQu" : address)
@mariano-aguero
mariano-aguero / bob.json
Created May 19, 2020 21:00
Wallet with some tokens
{
"mnemonic": [
"essence",
"crucial",
"useful",
"blush",
"phone",
"private",
"found",
"apple",
@mariano-aguero
mariano-aguero / owner.json
Last active June 26, 2020 17:33
Wallet that can mint tokens
{
"mnemonic": [
"pepper",
"elbow",
"pizza",
"best",
"speak",
"usual",
"mass",
"pepper",
@mariano-aguero
mariano-aguero / errors.ligo
Created May 15, 2020 12:47
Files with errors codes
// Error codes used with the `failwith` method , for contract execution termination.
const error_not_enough_balance : string = "0";
const error_transaction_of_funds_failed : string = "1";
const error_amount_must_be_zero : string = "3";
const emptyOps : list(operation) = list end;
function approve (const addressSpender : address; const value : nat; var store : store) : return is
block {
// If sender is the spender approving is not necessary
if sender = addressSpender then skip;
else block {
const senderAccount: account = getAccount(sender, store.accounts);
var allowance: nat := getAllowance(addressSpender, senderAccount.allowances);