Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix: add new Ethereum types namespace to fix types #2527

Merged
merged 43 commits into from
May 27, 2022
Merged

Conversation

davidmurdoch
Copy link
Member

@davidmurdoch davidmurdoch commented Mar 4, 2022

We fixed our Ethereum RPC types and put them in a new namespace: Ethereum! Use it as follows:

import Ganache, {ProviderOptions, Ethereum} from "ganache";

async function getLatestBlock(): Promise<Ethereum.Block> {
  return await provider.request({method: "eth_getBlockByNumber", params: ["latest"]});
}
async function getAccounts(): Promise<string[]> {
  return await provider.request({method: "eth_accounts", params: []});
}
async function sendTransaction(transaction: Ethereum.Transaction): Promise<string> {
  return await provider.request({method: "eth_sendTransaction", params: [transaction]});
}

const options: ProviderOptions = {
  fork: { network: "mainnet" }
};
const provider = Ganache.provider(options);
const accounts  = await getAccounts();
const block = await getLatestBlock();
console.log(block.number); // string
const transaction: Ethereum.Transaction = { from: accounts[0], to: accounts[2], value: "0xffff" };
const hash = await sendTransaction(transaction);
console.log(hash); // string

If you find issues or can think of ways we can further improve our types please open a New Issue (you can view all existing type issues by filtering our issues by the typescript label).

fixes #2134

@davidmurdoch davidmurdoch force-pushed the develop branch 2 times, most recently from 96d6c7f to 47d583d Compare April 8, 2022 17:42
@davidmurdoch davidmurdoch changed the title fix: types fix: fix types and add new Ethereum types namespace Apr 8, 2022
@davidmurdoch davidmurdoch force-pushed the fix-types branch 2 times, most recently from da81e97 to b91fc34 Compare April 20, 2022 00:33
@davidmurdoch davidmurdoch marked this pull request as ready for review April 20, 2022 20:08
@davidmurdoch davidmurdoch changed the title fix: fix types and add new Ethereum types namespace fix: add new Ethereum types namespace to fix types Apr 20, 2022
Copy link
Contributor

@MicaiahReid MicaiahReid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't pretend to understand those types tests, but they sure do look cool!

This was an initial pass through, I still haven't tested any of it.

src/chains/ethereum/block/src/block.ts Outdated Show resolved Hide resolved
// transactions
export type Transaction = TransactionTypes.Transaction;
export type CallTransaction = TransactionTypes.CallTransaction;
export type SignedTransaction<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having second thoughts about this name, SignedTransaction. That name made me think it was equivalent to a raw transaction, like what eth_signTransaction returns. :/

src/chains/ethereum/ethereum/src/api-types.ts Outdated Show resolved Hide resolved
src/chains/ethereum/ethereum/src/api.ts Outdated Show resolved Hide resolved
src/chains/ethereum/ethereum/src/api.ts Outdated Show resolved Hide resolved
src/chains/ethereum/ethereum/src/provider.ts Outdated Show resolved Hide resolved
src/packages/cli/src/cli.ts Outdated Show resolved Hide resolved
src/packages/ganache/tests/types.test.ts Outdated Show resolved Hide resolved
src/packages/ganache/tests/types.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@MicaiahReid MicaiahReid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excited to have this one merged! I've got some tiny clean up requests

src/chains/ethereum/ethereum/src/api-types.ts Outdated Show resolved Hide resolved
src/chains/ethereum/ethereum/src/api.ts Outdated Show resolved Hide resolved
src/chains/ethereum/ethereum/src/api.ts Outdated Show resolved Hide resolved
src/chains/ethereum/ethereum/src/api.ts Outdated Show resolved Hide resolved
src/packages/cli/src/cli.ts Outdated Show resolved Hide resolved
src/packages/ganache/tests/types.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@MicaiahReid MicaiahReid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!!

@davidmurdoch davidmurdoch merged commit 180da89 into develop May 27, 2022
@davidmurdoch davidmurdoch deleted the fix-types branch May 27, 2022 21:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ganache v7.0.0 - typings are broken
2 participants