-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from enitrat/feat/transfer-token
feat: starknet token transfer
- Loading branch information
Showing
7 changed files
with
1,147 additions
and
47 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
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
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,59 @@ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import { Account, Call, CallData, Calldata, Contract, cairo } from "starknet"; | ||
|
||
export type ApproveCall = { | ||
contractAddress: string; | ||
entrypoint: "approve"; | ||
calldata: Calldata; | ||
}; | ||
|
||
export type TransferCall = { | ||
contractAddress: string; | ||
entrypoint: "transfer"; | ||
calldata: Calldata; | ||
}; | ||
|
||
export class ERC20Token { | ||
abi: any; | ||
contract: Contract; | ||
calldata: CallData; | ||
constructor(token: string, account?: Account) { | ||
const erc20AbiPath = path.join(__dirname, "../utils/erc20.json"); | ||
const erc20Abi = JSON.parse(fs.readFileSync(erc20AbiPath, "utf8")); | ||
this.contract = new Contract(erc20Abi, token, account); | ||
this.calldata = new CallData(this.contract.abi); | ||
} | ||
|
||
public address() { | ||
return this.contract.address; | ||
} | ||
|
||
public async decimals() { | ||
const result = await this.contract.call("decimals"); | ||
return result as bigint; | ||
} | ||
|
||
|
||
public approveCall(spender: string, amount: bigint): ApproveCall { | ||
return { | ||
contractAddress: this.contract.address, | ||
entrypoint: "approve", | ||
calldata: this.calldata.compile("approve", { | ||
spender: spender, | ||
amount: cairo.uint256(amount), | ||
}), | ||
}; | ||
} | ||
|
||
public transferCall(recipient: string, amount: bigint): TransferCall { | ||
return { | ||
contractAddress: this.contract.address, | ||
entrypoint: "transfer", | ||
calldata: this.calldata.compile("transfer", { | ||
recipient: recipient, | ||
amount: cairo.uint256(amount), | ||
}), | ||
}; | ||
} | ||
} |
Oops, something went wrong.