Skip to content

Commit 306fb70

Browse files
feat(sdk-coin-starknet): add tokenContractAddress setter to TransferBuilder
Allow specifying a custom token contract address rather than using the hardcoded STRK_TOKEN_CONTRACT. Defaults to STRK. TICKET: CECHO-1165
1 parent 79f5a5d commit 306fb70

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

modules/sdk-coin-starknet/src/lib/transferBuilder.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import utils from './utils';
99
export class TransferBuilder extends TransactionBuilder {
1010
protected _receiverAddress?: string;
1111
protected _amount?: string;
12+
protected _tokenContractAddress: string = STRK_TOKEN_CONTRACT;
1213

1314
constructor(_coinConfig: Readonly<CoinConfig>) {
1415
super(_coinConfig);
@@ -35,6 +36,14 @@ export class TransferBuilder extends TransactionBuilder {
3536
return this;
3637
}
3738

39+
public tokenContractAddress(address: string): this {
40+
if (!address || !utils.isValidAddress(address)) {
41+
throw new BuildTransactionError('Invalid token contract address, got: ' + address);
42+
}
43+
this._tokenContractAddress = address;
44+
return this;
45+
}
46+
3847
/** @inheritdoc */
3948
initBuilder(tx: Transaction): void {
4049
super.initBuilder(tx);
@@ -43,6 +52,7 @@ export class TransferBuilder extends TransactionBuilder {
4352
if (transfer) {
4453
this._receiverAddress = transfer.recipient;
4554
this._amount = transfer.amount;
55+
this._tokenContractAddress = transfer.tokenContract;
4656
}
4757
}
4858
}
@@ -52,7 +62,7 @@ export class TransferBuilder extends TransactionBuilder {
5262
this.validateTransfer();
5363

5464
const transferCall: StarknetCall = {
55-
contractAddress: STRK_TOKEN_CONTRACT,
65+
contractAddress: this._tokenContractAddress,
5666
entrypoint: 'transfer',
5767
calldata: this.compileTransferCalldata(this._receiverAddress as string, this._amount as string),
5868
};

0 commit comments

Comments
 (0)