Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix: use correct programId when creating a custom Token
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Oct 21, 2018
1 parent b7726c2 commit 8d0dbf4
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/token-program.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ export class Token {
programId: PublicKey = SYSTEM_TOKEN_PROGRAM_ID,
): Promise<TokenAndPublicKey> {
const tokenAccount = new Account();
const token = new Token(connection, tokenAccount.publicKey);
const initialAccountPublicKey = (await token._newAccount(owner, null)).publicKey;
const token = new Token(connection, tokenAccount.publicKey, programId);
const initialAccountPublicKey = await token.newAccount(owner, null);

let transaction;

Expand Down Expand Up @@ -243,9 +243,16 @@ export class Token {
}

/**
* @private
* Create a new and empty token account.
*
* This account may then be used as a `transfer()` or `approve()` destination
*
* @param owner User account that will own the new token account
* @param source If not null, create a delegate account that when authorized
* may transfer tokens from this `source` account
* @return Public key of the new empty token account
*/
async _newAccount(owner: Account, source: null | PublicKey): Promise<Account> {
async newAccount(owner: Account, source: null | PublicKey = null): Promise<PublicKey> {
const tokenAccount = new Account();
let transaction;

Expand Down Expand Up @@ -282,23 +289,10 @@ export class Token {
programId: this.programId,
userdata,
});
await sendAndConfirmTransaction(this.connection, tokenAccount, transaction);

return tokenAccount;
}
await sendAndConfirmTransaction(this.connection, tokenAccount, transaction);

/**
* Create a new and empty token account.
*
* This account may then be used as a `transfer()` or `approve()` destination
*
* @param owner User account that will own the new token account
* @param source If not null, create a delegate account that when authorized
* may transfer tokens from this `source` account
* @return Public key of the new empty token account
*/
async newAccount(owner: Account, source: null | PublicKey = null): Promise<PublicKey> {
return (await this._newAccount(owner, source)).publicKey;
return tokenAccount.publicKey;
}

/**
Expand Down

0 comments on commit 8d0dbf4

Please sign in to comment.