Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type-based Celo fee currency PoC #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

shazarre
Copy link
Collaborator

@shazarre shazarre commented Feb 28, 2024

Aim of this PR is to show how support for fee currencies could be achieved using more type-based and network overrides object approach.

Because of the types it allows to specify feeCurrency on the top level of transaction request with proper typing support:

Screenshot 2024-02-29 at 12 13 42 Screenshot 2024-02-29 at 12 16 03 Screenshot 2024-02-29 at 12 17 39

To test it I used the following script that existed in a directory adjacent to directory to which ethers has been cloned to. I ran it using bun.

It requires dotenv to work and PRIVATE_KEY specified in .env file although can be modified to work without it.

It works with alfajores network only for now.

It also requires the sender to have sufficient funds to a) transfer CELO b) pay for the fee currency. Both can be acquired using the faucet.

import "dotenv/config";
import { celoAlfajores } from "../ethers.js/src.ts/chain/celo.ts";
import { createWallet } from "../ethers.js/src.ts/wallet/wallet.ts";
import { createJsonRpcProvider } from "../ethers.js/src.ts/providers/provider-jsonrpc.ts";

const provider = createJsonRpcProvider("https://alfajores-forno.celo-testnet.org", undefined, undefined, celoAlfajores);
const signer = createWallet(process.env.PRIVATE_KEY as string, provider, celoAlfajores);

let tx;

console.log("Try to send a CELO CIP-64 transaction...");
tx = await signer.sendTransaction({
    to: signer.address,
    value: 1n,
    feeCurrency: "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1",
});

// should be true
console.log(tx.type === 123);

console.log("Try to send an EIP-1559 transaction...");
tx = await signer.sendTransaction({
    to: signer.address,
    value: 1n,
});

// should be true
console.log(tx.type === 2);

When everything works correctly the script should output:

$ bun send.ts

Try to send a CELO CIP-64 transaction...
true
Try to send an EIP-1559 transaction...
true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant