|
| 1 | +import {Contract, type ContractRunner, type InterfaceAbi, type BigNumberish, type TransactionResponse} from 'ethers' |
| 2 | + |
| 3 | +export const ERC721_ABI: InterfaceAbi = [ |
| 4 | + 'function name() view returns (string)', |
| 5 | + 'function symbol() view returns (string)', |
| 6 | + 'function ownerOf(uint256 tokenId) view returns (address)', |
| 7 | + 'function tokenURI(uint256 tokenId) view returns (string)', |
| 8 | + 'function transferFrom(address from, address to, uint256 tokenId)', |
| 9 | + 'function safeTransferFrom(address from, address to, uint256 tokenId)', |
| 10 | +] |
| 11 | + |
| 12 | +export default class ERC721 { |
| 13 | + public contract: Contract |
| 14 | + |
| 15 | + constructor(address: string, runner: ContractRunner) { |
| 16 | + this.contract = new Contract(address, ERC721_ABI, runner) |
| 17 | + } |
| 18 | + |
| 19 | + name(): Promise<string> { |
| 20 | + return this.contract.name() |
| 21 | + } |
| 22 | + |
| 23 | + symbol(): Promise<string> { |
| 24 | + return this.contract.symbol() |
| 25 | + } |
| 26 | + |
| 27 | + ownerOf(tokenId: BigNumberish): Promise<string> { |
| 28 | + return this.contract.ownerOf(tokenId) |
| 29 | + } |
| 30 | + |
| 31 | + tokenURI(tokenId: BigNumberish): Promise<string> { |
| 32 | + return this.contract.tokenURI(tokenId) |
| 33 | + } |
| 34 | + |
| 35 | + transferFrom(from: string, to: string, tokenId: BigNumberish): Promise<TransactionResponse> { |
| 36 | + return this.contract.transferFrom(from, to, tokenId) |
| 37 | + } |
| 38 | + |
| 39 | + safeTransferFrom(from: string, to: string, tokenId: BigNumberish): Promise<TransactionResponse> { |
| 40 | + return this.contract.safeTransferFrom(from, to, tokenId) |
| 41 | + } |
| 42 | +} |
0 commit comments