-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// read | ||
export { balanceOf } from "./erc20/balanceOf.js"; | ||
export { decimals } from "./erc20/decimals.js"; | ||
// write | ||
export { mintTo } from "./erc20/mintTo.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { transaction } from "../../transaction/index.js"; | ||
import type { ThirdwebContract } from "../../contract/index.js"; | ||
import { read } from "../../transaction/actions/read.js"; | ||
|
||
type BalanceOfParams = { address: string }; | ||
|
||
export async function balanceOf( | ||
contract: ThirdwebContract, | ||
options: BalanceOfParams, | ||
) { | ||
return read( | ||
transaction(contract, { | ||
address: contract.address, | ||
chainId: contract.chainId, | ||
method: "function balanceOf(address) view returns (uint256)", | ||
params: [options.address], | ||
}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { transaction } from "../../transaction/index.js"; | ||
import type { ThirdwebContract } from "../../contract/index.js"; | ||
import { read } from "../../transaction/actions/read.js"; | ||
|
||
export async function decimals(contract: ThirdwebContract) { | ||
return read( | ||
transaction(contract, { | ||
address: contract.address, | ||
chainId: contract.chainId, | ||
method: "function decimals() view returns (uint8)", | ||
}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { transaction } from "../../transaction/index.js"; | ||
import type { ThirdwebContract } from "../../contract/index.js"; | ||
|
||
type MintToParams = { to: string } & ( | ||
| { | ||
amount: number; | ||
} | ||
| { | ||
amountGwei: bigint; | ||
} | ||
); | ||
|
||
export function mintTo(contract: ThirdwebContract, options: MintToParams) { | ||
return transaction(contract, { | ||
address: contract.address, | ||
chainId: contract.chainId, | ||
method: "function mintTo(address to, uint256 amount)", | ||
params: async () => { | ||
let amount: bigint; | ||
if ("amount" in options) { | ||
// if we need to parse the amount from ether to gwei then we pull in the decimals extension | ||
const { decimals } = await import("./decimals.js"); | ||
// if this fails we fall back to `18` decimals | ||
const d = await decimals(contract).catch(() => 18); | ||
// turn ether into gwei | ||
amount = BigInt(options.amount) * 10n ** BigInt(d); | ||
} else { | ||
amount = options.amountGwei; | ||
} | ||
return [options.to, amount] as const; | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters