# Ethereum API
## Contracts
### Get Instance with address
eth: `new ethers.Contract(address, abi, provider | signer);`
ae: `await aeSdk.getContractInstance({ contractAddress, source?, aci?, bytecode? });`
### Get Instance without address
eth: `new ethers.ContractFactory(abi, bytecode, provider | signer);`
ae: `await aeSdk.getContractInstance({ source?, aci?, bytecode? });`
### Deploy
eth:
```
const factory = new ethers.ContractFactory(abi, bytecode, signer);
const contract = await factory.deploy(args);
await contract.deployTransaction.wait();
```
ae:
```
const contract = await aeSdk.initializeContract({ sourceCode });
await contract.$deploy(args);
```
### Call Method
eth: `await contract.method(...args);`
ae: `await contract.method(...args, { callStatic?: boolean });`
## Transactions
### Build
eth: https://docs.ethers.io/v5/cookbook/transactions/
ae: `await aeSdk.buildTx(type, args);`
### Sign
eth: `await signer.signTransaction({ raw } | args)`
ae: `await aeSdk.signTransaction(rawTx);`
### Submit
eth: `N/A` (there seems no way to simply publish a raw signed tx)
ae: `await aeSdk.sendTransaction(signedTx);` or `await aeSdk.api.postTransaction({ tx });`
### SpendTx (Should be fairly easy)
eth: `await provider.send('eth_sendTransaction', { from, to, value })`
ae: `await aeSdk.spend(amount, address)`
## Sign Payload
eth: `await signer.signMessage(message)`
ae: `await sdk.signMessage(message);`
## Get
### Height
eth: `await provider.getBlockNumber()`
ae: `await aeSdk.height();`
### Blocks by Hash
eth: `await provider.getBlock(hash)`
ae: ` await aeSdk.getKeyBlock(hash)`
### Blocks by Number
eth: `await provider.getBlock(number)`
ae: ` await aeSdk.getKeyBlock(number)`
### Balance
eth: `await provider.getBalance(address)`
ae: `await aeSdk.getBalance(address)`
### Account (aka Signer) Address
eth: `await signer.getAddress()`
ae: `aeSdk.address()`
### Transactions by Hash
eth: `await provider.getTransaction(hash)`
ae: `await aeSdk.getTxInfo(hash)`
## ENS / AENS
### Resolve Name
eth: `await provider.resolveName(name)`
ae: `await aeSdk.resolveName(name)`
### Get Name Entry
eth: `N/A`
ae: `await aeSdk.getName(name)`
### Reverse Lookup
eth: `await provider.lookupAddress(address)`
ae: `N/A`
# Return Types
## Create a TX on chain
eth:
```
Transaction
hash: string<32>
to: address
from: address
nonce: number
gasLimit: BigNumber
gasPrice: BigNumber | null
maxFeePerGas: BigNumber
maxPriorityFeePerGas: BigNumber | null
data: Bytes
value: BigNumber
chainId: number (EIP155)
TransactionResponse extends Transaction
blockNumber: int | null
blockHash: string<32> | null
timestamp: int | null
confirmations: int | null
raw: string
wait(confirms): function --> TransactionReceipt
type: number (according to EIP2718)
accessList: array<string<32>> (according to EIP-2930)
TransactionReceipt
to: address | null
from: address
contractAddress: address | null
transactionIndex: number
type: number (EIP2718)
root: string (deprecated)
gasUsed: BigNumber
effectiveGasPrice: BigNumber
logsBloom: string
blockHash: string<32>
transactionHash: string<32>
logs: array<Log>
blockNumber: number
confirmations: number
cumulativeGasUsed: BigNumber
byzantium: boolean
status: tinyint
Log
blockNumber: number
blockHash: string<32>
removed: boolean
transactionLogIndex: number
address: string<32>
data: string
topics: array<string<32>>
transactionHash: string<32>
transactionIndex: number
logIndex: number #The index of this log across all logs in the entire block.
```
ae: https://github.com/aeternity/aepp-sdk-js/blob/a4df699f/src/tx/builder/schema.ts#L197
## Can they be merged?
### Transaction
| eth | ae | comment |
| -------- | -------- | -------- |
| hash: string<32> | hash: string |
| to: address | toId: string |
| from: address | fromId: string |
| nonce: number | nonce: number |
| gasLimit: BigNumber | gasLimit: number |
| gasPrice: BigNumber | gasPrice: bigint | legacy option on eth |
| maxFeePerGas: BigNumber | gasPrice: bigint | amount of base fee + tip |
| maxPriorityFeePerGas: BigNumber | N/A | size of the tip added to the base fee |
| data: Bytes | payload: string | could also be callData depending on the ethers implementation |
| value: BigNumber | amount: bigint | or fee sometimes |
| chainId: number (EIP155) | N/A | this is part of the signature in ae |
### TransactionResponse
| eth | ae | comment |
| -------- | -------- | -------- |
| blockNumber: int | blockHeight: int | |
| blockHash: string<32> | blockHash: string | |
| timestamp: int | N/A | only available on block level |
| confirmations: int | N/A | can be calculated |
| raw: string | rawTx: string | |
| type: number | N/A | can be determined by attributes or just 0 |
| accessList: array<string<32>> | N/A | not implemented on ae |
### TransactionReceipt
| eth | ae | comment |
| -------- | -------- | -------- |
| to: address | toId: string |
| from: address | fromId: string |
| contractAddress: address | contractId: string |
| transactionIndex: number | N/A | does not exist in ae |
| type: number | N/A | can be determined by attributes or just 0 |
| root: string | N/A | can be skipped, legacy field |
| gasUsed: BigNumber | gas: number |
| effectiveGasPrice: BigNumber | gasPrice: bigint |
| logsBloom: string | N/A | TBD |
| blockHash: string<32> | blockHash: string | |
| transactionHash: string<32> | hash: string |
| logs: array<Log> | log | has to be decoded but values are available |
| blockNumber: number | blockHeight: int |
| confirmations: number | N/A | can be calculated |
| cumulativeGasUsed: BigNumber | N/A | same as gas |
| byzantium: boolean | N/A | can be simply false
| status: tinyint | returnType | only available on contract tx, for other tx it can be inferred | |