Skip to main content
Version: Next

@keypom/core - v1.0.2

Interfaces

Type Aliases

AnyWallet

AnyWallet: BrowserWalletBehaviour | Wallet | Promise<Wallet>

Defined in

lib/types/params.ts:19


NearKeyPair

NearKeyPair: KeyPair

Defined in

lib/types/general.ts:12

Variables

TRIAL_ERRORS

Const TRIAL_ERRORS: Object

Type declaration

NameType
EXIT_EXPECTEDstring
INSUFFICIENT_BALANCEstring
INVALID_ACTIONstring

Defined in

lib/trial-accounts/utils.ts:13


networks

Const networks: Object

Type declaration

NameType
localnet{ networkId: string = 'localnet'; viewAccountId: string = 'test.near' }
localnet.networkIdstring
localnet.viewAccountIdstring
mainnet{ helperUrl: string = 'https://helper.mainnet.near.org'; networkId: string = 'mainnet'; nodeUrl: string = 'https://rpc.mainnet.near.org'; viewAccountId: string = 'near'; walletUrl: string = 'https://wallet.near.org' }
mainnet.helperUrlstring
mainnet.networkIdstring
mainnet.nodeUrlstring
mainnet.viewAccountIdstring
mainnet.walletUrlstring
testnet{ helperUrl: string = 'https://helper.testnet.near.org'; networkId: string = 'testnet'; nodeUrl: string = 'https://rpc.testnet.near.org'; viewAccountId: string = 'testnet'; walletUrl: string = 'https://wallet.testnet.near.org' }
testnet.helperUrlstring
testnet.networkIdstring
testnet.nodeUrlstring
testnet.viewAccountIdstring
testnet.walletUrlstring

Defined in

lib/keypom.ts:25

Keypom SDK Environment

accountMappingContract

Const accountMappingContract: Object

Recovery mapping contracts used to keep track of trial account IDs for given public keys.

Type declaration

NameType
mainnetstring
testnetstring

Defined in

lib/keypom.ts:93


supportedKeypomContracts

Const supportedKeypomContracts: Object

List of supported Keypom contracts that can be used with the SDK.

Type declaration

NameType
localnet{ keypom.test.near: boolean = true }
localnet.keypom.test.nearboolean
mainnet{ v1-3.keypom.near: boolean = false; v1-4.keypom.near: boolean = true; v1.keypom.near: boolean = false; v2.keypom.near: boolean = true }
mainnet.v1-3.keypom.nearboolean
mainnet.v1-4.keypom.nearboolean
mainnet.v1.keypom.nearboolean
mainnet.v2.keypom.nearboolean
testnet{ v1-3.keypom.testnet: boolean = false; v1-4.keypom.testnet: boolean = true; v1.keypom.testnet: boolean = false; v2.keypom.testnet: boolean = true }
testnet.v1-3.keypom.testnetboolean
testnet.v1-4.keypom.testnetboolean
testnet.v1.keypom.testnetboolean
testnet.v2.keypom.testnetboolean

Defined in

lib/keypom.ts:51


supportedLinkdropClaimPages

Const supportedLinkdropClaimPages: Object

Official linkdrop claim pages for wallets and other applications

Type declaration

NameType
mainnet{ keypom: string = 'https://keypom.xyz/claim/CONTRACT\_ID#SECRET\_KEY'; meteor: string = 'https://wallet.meteorwallet.app/linkdrop/CONTRACT\_ID/SECRET\_KEY'; mynearwallet: string = 'https://app.mynearwallet.com/linkdrop/CONTRACT\_ID/SECRET\_KEY' }
mainnet.keypomstring
mainnet.meteorstring
mainnet.mynearwalletstring
testnet{ keypom: string = 'https://testnet.keypom.xyz/claim/CONTRACT\_ID#SECRET\_KEY'; meteor: string = 'https://wallet.meteorwallet.app/linkdrop/CONTRACT\_ID/SECRET\_KEY'; mynearwallet: string = 'https://testnet.mynearwallet.com/linkdrop/CONTRACT\_ID/SECRET\_KEY' }
testnet.keypomstring
testnet.meteorstring
testnet.mynearwalletstring

Defined in

lib/keypom.ts:74


getEnv

getEnv(): EnvVars

Returns

EnvVars

The environment variables used by the Keypom library.

Defined in

lib/keypom.ts:119


initKeypom

initKeypom(«destructured»): Promise<any>

Initializes the SDK to allow for interactions with the Keypom Protocol. By default, a new NEAR connection will be established but this can be overloaded by passing in an existing connection object. In either case, if a funder is passed in, the credentials will be added to the keystore to sign transactions.

To update the funder account, refer to the updateFunder function. If you only wish to use view methods and not sign transactions, no funder account is needed. If you wish to update the Keypom Contract ID being used, refer to the updateKeypomContractId function.

Example

Using a pre-created NEAR connection instance with an UnencryptedFileSystemKeyStore:

const path = require("path");
const homedir = require("os").homedir();
const { KeyPair, keyStores, connect } = require("near-api-js");
const { initKeypom, getDrops } = require("keypom-js");

// Establish the network we wish to work on
const network = "testnet";
// Get the location where the credentials are stored for our KeyStore
const CREDENTIALS_DIR = ".near-credentials";
const credentialsPath = (await path).join(homedir, CREDENTIALS_DIR);
(await path).join;
let keyStore = new keyStores.UnencryptedFileSystemKeyStore(credentialsPath);

// Establish the configuration for the connection
let nearConfig = {
networkId: network,
keyStore,
nodeUrl: `https://rpc.${network}.near.org`,
walletUrl: `https://wallet.${network}.near.org`,
helperUrl: `https://helper.${network}.near.org`,
explorerUrl: `https://explorer.${network}.near.org`,
};
// Connect to the NEAR blockchain and get the connection instance
let near = await connect(nearConfig);

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
near,
network
});

// Get the drops for the given owner
const dropsForOwner = await getDrops({accountId: "benjiman.testnet"});

Example

Creating an entirely new NEAR connection instance by using initKeypom and passing in a funder account:

const { initKeypom, getDrops } = require("keypom-js");

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Get the drops for the given owner
const dropsForOwner = await getDrops({accountId: "benjiman.testnet"});

Parameters

NameTypeDescription
«destructured»Object-
› funder?FunderThe account that will sign transactions to create drops and interact with the Keypom contract. This account will be added to the KeyStore if provided. If rootEntropy is provided for the funder, all access keys will be derived deterministically based off this string.
› keypomContractId?stringInstead of using the most up-to-date, default Keypom contract, you can specify a specific account ID to use. If an older version is specified, some features of the SDK might not be usable.
› near?NearThe NEAR connection instance to use. If not passed in, it will create a new one.
› network?stringThe network to connect to either mainnet or testnet. If a near object is passed in, this field can be omitted

Returns

Promise<any>

If a funder is passed in, its account object is returned. Otherwise, it null is returned.

Defined in

lib/keypom.ts:239


updateFunder

updateFunder(funder): Promise<any>

Once the SDK is initialized, this function allows the current funder account to be updated. Having a funder is only necessary if you wish to sign transactions on the Keypom Protocol.

Example

After initializing the SDK, the funder is updated.

const path = require("path");
const homedir = require("os").homedir();
const { KeyPair, keyStores, connect } = require("near-api-js");
const { initKeypom, updateFunder, getDrops } = require("keypom-js");

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
});

// Update the current funder account
await updateFunder({
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
})

// Get the drops for the given owner
const dropsForOwner = await getDrops({accountId: "benjiman.testnet"});
console.log('dropsForOwner: ', dropsForOwner)

return;

Parameters

NameTypeDescription
funderObjectThe account that will sign transactions to create drops and interact with the Keypom contract. This account will be added to the KeyStore if provided. If rootEntropy is provided for the funder, all access keys will be derived deterministically based off this string.
funder.funderFunder-

Returns

Promise<any>

The funder's account object is returned.

Defined in

lib/keypom.ts:369


updateKeypomContractId

updateKeypomContractId(keypomContractId): any

This allows the desired Keypom contract ID to be set. By default, the most up-to-date Keypom contract for the given network is set during initKeypom.

Example

After initializing the SDK, the Keypom contract ID is updated.

const path = require("path");
const homedir = require("os").homedir();
const { KeyPair, keyStores, connect } = require("near-api-js");
const { initKeypom, updateKeypomContractId, getDrops } = require("keypom-js");

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
});

// Update the current Keypom contract ID
updateKeypomContractId({
keypomContractId: "v1.keypom.testnet"
})

//Get the drops for the given owner
const dropsForOwner = await getDrops({accountId: "benjiman.testnet"});
console.log('dropsForOwner: ', dropsForOwner)

return;

Parameters

NameTypeDescription
keypomContractIdObjectThe account ID that should be used for the Keypom contract.
keypomContractId.keypomContractIdstring-

Returns

any

Defined in

lib/keypom.ts:430

Utility

accountExists

accountExists(accountId): Promise<boolean>

Check whether or not a given account ID exists on the network.

Example

const accountExists = await accountExists("benji.near");
console.log(accountExists); // true

Parameters

NameTypeDescription
accountIdanyThe account ID you wish to check

Returns

Promise<boolean>

  • A boolean indicating whether or not the account exists

Defined in

lib/keypom-utils.ts:87


createNFTSeries

createNFTSeries(«destructured»): Promise<void | FinalExecutionOutcome[]>

Creates a new NFT series on the official Keypom Series contracts. This is for lazy minting NFTs as part of an FC drop.

Example

Send 3 NFTs using the funder account (not passing in any accounts into the call):

    await initKeypom({
// near,
network: 'testnet',
funder: {
accountId,
secretKey,
}
})

const {keys, dropId} = await createDrop({
numKeys: 1,
config: {
usesPerKey: 100
},
metadata: "My Cool Drop Title!",
depositPerUseNEAR: 0.5,
fcData: {
methods: [[
{
receiverId: `nft-v2.keypom.testnet`,
methodName: "nft_mint",
args: "",
dropIdField: "mint_id",
accountIdField: "receiver_id",
attachedDeposit: parseNearAmount("0.1")
}
]]
}
})

const res = await createNFTSeries({
dropId,
metadata: {
title: "Moon NFT!",
description: "A cool NFT for the best dog in the world.",
media: "bafybeibwhlfvlytmttpcofahkukuzh24ckcamklia3vimzd4vkgnydy7nq",
copies: 500
}
});
console.log('res: ', res)

const URLs = formatLinkdropUrl({
baseUrl: "localhost:3000/claim",
secretKeys: keys.secretKeys
})
console.log('URLs: ', URLs)

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› dropIdstringThe drop ID for the drop that should have a series associated with it.
› metadataNonFungibleTokenMetadataThe metadata that all minted NFTs will have.
› royalty?Map<string, number>Any royalties associated with the series (as per official NEP-199 standard: https://github.com/near/NEPs/blob/master/neps/nep-0199.md)
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<void | FinalExecutionOutcome[]>

Defined in

lib/keypom-utils.ts:227


estimateRequiredDeposit

estimateRequiredDeposit(«destructured»): Promise<string>

Initiate the connection to the NEAR blockchain.

Parameters

NameTypeDescription
«destructured»Object-
› attachedGasnumberHow much Gas will be attached to each key's use.
› depositPerUsestringHow much yoctoNEAR each key will transfer upon use.
› fcData?FCDataThe FC data for the drop that is being created.
› ftData?FTDataThe FT data for the drop that is being created.
› keyStorage?stringHow much storage an individual key uses.
› nearNearThe NEAR connection instance used to interact with the chain. This can either the connection that the SDK uses from getEnv or a separate connection.
› numKeysnumberHow many keys are being added to the drop.
› storage?stringThe estimated storage costs (can be retrieved through getStorageBase).
› usesPerKeynumberHow many uses each key has.

Returns

Promise<string>

Defined in

lib/keypom-utils.ts:1162


execute

execute(args): Promise<void | FinalExecutionOutcome[] | (void | FinalExecutionOutcome)[]>

Parameters

NameType
argsany

Returns

Promise<void | FinalExecutionOutcome[] | (void | FinalExecutionOutcome)[]>

Defined in

lib/keypom.ts:147


formatLinkdropUrl

formatLinkdropUrl(«destructured»): string[]

Constructs a valid linkdrop URL for a given claim page or custom URL. To view the list of supported claim pages, see the exported supportedLinkdropClaimPages variable.

Example

Use the keypom claim page:

await initKeypom({
network: 'testnet',
funder: {
accountId,
secretKey,
}
})

const {keys} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1
});

const linkdropUrl = formatLinkdropUrl({
claimPage: "keypom",
contractId: "v2.keypom.testnet",
secretKeys: keys.secretKeys[0] // Can be either the array or individual secret key string
})

console.log('linkdropUrl: ', linkdropUrl)

Example

Use a custom claim page with ONLY the secret key

await initKeypom({
network: 'testnet',
funder: {
accountId,
secretKey,
}
})

const {keys} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1
});

const linkdropUrl = formatLinkdropUrl({
customURL: "foobar/SECRET_KEY/barfoo",
contractId: "v2.keypom.testnet",
secretKeys: keys.secretKeys[0] // Can be either the array or individual secret key string
})

console.log('linkdropUrl: ', linkdropUrl)

Example

Use a custom claim page with both the secret key and contract ID

await initKeypom({
network: 'testnet',
funder: {
accountId,
secretKey,
}
})

const {keys} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1
});

const linkdropUrl = formatLinkdropUrl({
customURL: "foobar/SECRET_KEY/barfoo/CONTRACT_ID",
contractId: "v2.keypom.testnet",
secretKeys: keys.secretKeys[0] // Can be either the array or individual secret key string
})

console.log('linkdropUrl: ', linkdropUrl)

Parameters

NameType
«destructured»Object
› claimPage?string
› contractId?string
› customURL?string
› networkId?string
› secretKeysstring | string[]

Returns

string[]

  • An array of the linkdrop URLs

Defined in

lib/keypom-utils.ts:384


generateKeys

generateKeys(«destructured»): Promise<GeneratedKeyPairs>

Generate ed25519 KeyPairs that can be used for Keypom linkdrops, or full access keys to claimed accounts. These keys can optionally be derived from some entropy such as a root password and metadata pertaining to each key (user provided password etc.). Entropy is useful for creating an onboarding experience where in order to recover a keypair, the client simply needs to provide the meta entropy (could be a user's password) and the secret root key like a UUID).

Example

Generating 10 unique random keypairs with no entropy:

// Generate 10 keys with no entropy (all random)
let keys = await generateKeys({
numKeys: 10,
})

let pubKey1 = keys.publicKeys[0];
let secretKey1 = keys.secretKeys[0];

console.log('1st Public Key: ', pubKey1);
console.log('1st Secret Key: ', secretKey1)

Example

Generating 1 keypair based on entropy:

// Generate 1 key with the given entropy
let {publicKeys, secretKeys} = await generateKeys({
numKeys: 1,
rootEntropy: "my-global-password",
metaEntropy: "user-password-123" // In this case, since there is only 1 key, the entropy can be an array of size 1 as well.
})

let pubKey = publicKeys[0];
let secretKey = secretKeys[0];

console.log('Public Key: ', pubKey);
console.log('Secret Key: ', secretKey)

Example

Generating 2 keypairs each with their own entropy:

// Generate 2 keys each with their own unique entropy
let keys = await generateKeys({
numKeys: 2,
rootEntropy: "my-global-password",
metaEntropy: [
`first-password:0`,
`second-password:1`
]
})

console.log('Pub Keys ', keys.publicKeys);
console.log('Secret Keys ', keys.secretKeys);

Example

Generate 50 keys exactly how the auto key generation would in createDrop and addKeys:

const dropId = '1676913490360';
const basePassword = "my-password";
// Generate 50 keys each with their own unique entropy
let keys = await generateKeys({
numKeys: 50,
rootEntropy: `${basePassword}-${dropId}`,
autoMetaNonceStart: 0
})

console.log('Pub Keys ', keys.publicKeys);
console.log('Secret Keys ', keys.secretKeys);

Parameters

NameTypeDescription
«destructured»Object-
› autoMetaNonceStart?number-
› metaEntropy?string | string[]An array of entropies to use in conjunction with a base rootEntropy to deterministically generate the private keys. For single key generation, you can either pass in a string array with a single element, or simply pass in the string itself directly (not within an array).
› numKeysnumberThe number of keys to generate.
› rootEntropy?stringA root string that will be used as a baseline for all keys in conjunction with different metaEntropies (if provided) to deterministically generate a keypair. If not provided, the keypair will be completely random.

Returns

Promise<GeneratedKeyPairs>

  • An object containing an array of KeyPairs, Public Keys and Secret Keys.

Defined in

lib/keypom-utils.ts:536


generatePerUsePasswords

generatePerUsePasswords(«destructured»): Promise<PasswordPerUse[][]>

Generate passwords for a set of public keys. A unique password will be created for each specified use of a public key where the use is NOT zero indexed (i.e 1st use = 1). The passwords will be generated via a double hash of the base password + public key + specific use

Parameters

NameType
«destructured»Object
› basePasswordstring
› publicKeysstring[]
› usesnumber[]

Returns

Promise<PasswordPerUse[][]>

An array of objects for each key where each object has a password and maps it to its specific key use.

Defined in

lib/keypom-utils.ts:1358


getFTMetadata

getFTMetadata(contractId): Promise<FungibleTokenMetadata>

Get the FT Metadata for a given fungible token contract. This is used to display important information such as the icon for the token, decimal format etc.

Example

const ft = await getFTMetadata({
contractId: "ft.keypom.testnet"
});
console.log(ft);

Parameters

NameTypeDescription
contractIdObjectThe contract ID of the FT contract
contractId.contractIdstring-

Returns

Promise<FungibleTokenMetadata>

  • The FT Metadata

Defined in

lib/keypom-utils.ts:156


getNFTMetadata

getNFTMetadata(«destructured»): Promise<ProtocolReturnedNonFungibleTokenObject>

Get the NFT Object (metadata, owner, approval IDs etc.) for a given token ID on a given contract.

Example

const nft = await getNFTMetadata({
contractId: "nft.keypom.testnet",
tokenId: "1"
});
console.log(nft);

Parameters

NameType
«destructured»Object
› contractIdstring
› tokenIdstring

Returns

Promise<ProtocolReturnedNonFungibleTokenObject>

  • The NFT Object

Defined in

lib/keypom-utils.ts:120


getPubFromSecret

getPubFromSecret(secretKey): string

Get the public key from a given secret key.

Example

const pubKey = getPubFromSecret("ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1");
console.log(pubKey);

Parameters

NameTypeDescription
secretKeystringThe secret key you wish to get the public key from

Returns

string

  • The public key

Defined in

lib/keypom-utils.ts:68


getStorageBase

getStorageBase(«destructured»): string

Parameters

NameType
«destructured»CreateDropProtocolArgs

Returns

string

Defined in

lib/keypom-utils.ts:1073


hashPassword

hashPassword(str, fromHex?): Promise<string>

Generate a sha256 hash of a passed in string. If the string is hex encoded, set the fromHex flag to true.

Example

Generating the required password to pass into claim given a base password:

    // Create the password to pass into claim which is a hash of the basePassword, public key and whichever use we are on
let currentUse = 1;
let passwordForClaim = await hashPassword(basePassword + publicKey + currentUse.toString());

Parameters

NameTypeDefault valueDescription
strstringundefinedthe string you wish to hash. By default, this should be utf8 encoded. If the string is hex encoded, set the fromHex flag to true.
fromHexbooleanfalse(OPTIONAL) - A flag that should be set if the string is hex encoded. Defaults to false.

Returns

Promise<string>

  • The resulting hash

Defined in

lib/keypom-utils.ts:451


viewAccessKeyData

viewAccessKeyData(«destructured»): Promise<any>

Query for important access key data such as the nonce, allowance, method names etc. that is stored on the NEAR protocol for a given account and public key.

Example

Check if an access key belongs to a trial account

const keyInfo = await viewAccessKeyData({accountId, secretKey});
let keyPerms = keyInfo.permission.FunctionCall;
isValidTrialInfo = keyPerms.receiver_id === accountId && keyPerms.method_names.includes('execute')
console.log('isValidTrialInfo: ', isValidTrialInfo)

Parameters

NameTypeDescription
«destructured»Object-
› accountIdstringThe account that the access key belongs to.
› publicKey?stringThe public key of the access key
› secretKey?stringThe secret key of the access key

Returns

Promise<any>

Defined in

lib/keypom-utils.ts:623

Creating, And Claiming Drops

addKeys

addKeys(«destructured»): Promise<CreateOrAddReturn>

Add keys that are manually generated and passed in, or automatically generated to an existing drop. If they're automatically generated, they can be based off a set of entropy. For NFT and FT drops, assets can automatically be sent to Keypom to register keys as part of the payload. The deposit is estimated based on parameters that are passed in and the transaction can be returned instead of signed and sent to the network. This can allow you to get the required deposit from the return value and use that to fund the account's Keypom balance to avoid multiple transactions being signed in the case of a drop with many keys.

Example

Create a basic empty simple drop and add 10 keys. Each key is completely random:

// Initialize the SDK for the given network and NEAR connection. No entropy passed in so any auto generated keys will
// be completely random unless otherwise overwritten.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create an empty simple drop with no keys.
const {dropId} = await createDrop({
depositPerUseNEAR: 1,
});

// Add 10 completely random keys. The return value `keys` contains information about the generated keys
const {keys} = await addKeys({
dropId,
numKeys: 10
})

console.log('public keys: ', keys.publicKeys);
console.log('private keys: ', keys.secretKeys);

Example

Init funder with root entropy, create empty drop and add generate deterministic keys. Compare with manually generated keys:

// Initialize the SDK for the given network and NEAR connection. Root entropy is passed into the funder account so any generated keys
// Will be based off that entropy.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1",
rootEntropy: "my-global-secret-password"
}
});

// Create a simple drop with no keys
const { dropId } = await createDrop({
depositPerUseNEAR: 1,
});

// Add 5 keys to the empty simple drop. Each key will be derived based on the rootEntropy of the funder, the drop ID, and key nonce.
const {keys: keysFromDrop} = await addKeys({
dropId,
numKeys: 5
})

// Deterministically Generate the Private Keys:
const nonceDropIdMeta = Array.from({length: 5}, (_, i) => `${dropId}_${i}`);
const manualKeys = await generateKeys({
numKeys: 5,
rootEntropy: "my-global-secret-password",
metaEntropy: nonceDropIdMeta
})

// Get the public and private keys from the keys generated by addKeys
const {publicKeys, secretKeys} = keysFromDrop;
// Get the public and private keys from the keys that were manually generated
const {publicKeys: pubKeysGenerated, secretKeys: secretKeysGenerated} = manualKeys;
// These should match!
console.log('secretKeys: ', secretKeys)
console.log('secretKeysGenerated: ', secretKeysGenerated)

// These should match!
console.log('publicKeys: ', publicKeys)
console.log('pubKeysGenerated: ', pubKeysGenerated)

Example

Create an empty drop and add manually created keys:

// Initialize the SDK for the given network and NEAR connection. No entropy passed in so any auto generated keys will
// be completely random unless otherwise overwritten.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create an empty simple drop using the keys that were generated. Since keys are passed in, the return value won't contain information about the keys.
const {dropId} = await createDrop({
publicKeys,
depositPerUseNEAR: 1,
});

// Generate 10 random keys
const {publicKeys} = await generateKeys({
numKeys: 10
});

// Add keys to the drop using the keys that were generated. Since keys are passed in, the return value won't contain information about the keys.
await addKeys({
publicKeys,
dropId
})

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› basePassword?stringFor doing password protected drops, this is the base password that will be used to generate all the passwords. It will be double hashed with the public keys. If specified, by default, all key uses will have their own unique password unless passwordProtectedUses is passed in.
› drop?ProtocolReturnedDropIf the drop information from getDropInformation is already known to the client, it can be passed in instead of the drop ID to reduce computation.
› dropId?stringSpecify the drop ID for which you want to add keys to.
› extraDepositNEAR?numberFor Public Sales, drops might require an additional fee for adding keys. This specifies the amount of $NEAR in human readable format (i.e 1.5 = 1.5 $NEAR)
› extraDepositYocto?stringFor Public Sales, drops might require an additional fee for adding keys. This specifies the amount of $NEAR in yoctoNEAR (i.e 1 = 1 $yoctoNEAR = 1e-24 $NEAR)
› nftTokenIds?string[]If the drop type is an NFT drop, the token IDs can be passed in so that the tokens are automatically sent to the Keypom contract rather than having to do two separate transactions. A maximum of 2 token IDs can be sent during the addKeys function. To send more token IDs in order to register key uses, use the nftTransferCall function.
› numKeysnumberSpecify how many keys should be generated for the drop. If the funder has rootEntropy set OR rootEntropy is passed in, the keys will be deterministically generated using the drop ID, key nonce, and entropy. Otherwise, each key will be generated randomly.
› passwordProtectedUses?number[]For doing password protected drops, specifies exactly which uses will be password protected. The uses are NOT zero indexed (i.e 1st use = 1). Each use will have a different, unique password generated via double hashing the base password + public key + key use.
› publicKeys?string[]Pass in a custom set of publicKeys to add to the drop. If this is not passed in, keys will be generated based on the numKeys parameter.
› returnTransactions?booleanIf true, the transaction will be returned instead of being signed and sent. This is useful for getting the requiredDeposit from the return value without actually signing the transaction.
› rootEntropy?stringSpecify an entropy to use for generating keys (will overload the funder's rootEntropy if applicable). This parameter only matters if the publicKeys variable is not passed in.
› useBalance?booleanIf the account has a balance within the Keypom contract, set this to true to avoid the need to attach a deposit. If the account doesn't have enough balance, an error will throw.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<CreateOrAddReturn>

Object containing: the drop ID, the responses of the execution, as well as any auto generated keys (if any).

Defined in

lib/keys.ts:148


claim

claim(«destructured»): Promise<any>

Allows a specific Keypom drop to be claimed via the secret key.

Example

Creating a simple $NEAR drop and claiming to an existing account:

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// create 1 keys with no entropy (random key)
const {publicKeys, secretKeys} = await generateKeys({
numKeys: 1
});

// Create a simple drop with 1 $NEAR
await createDrop({
publicKeys,
depositPerUseNEAR: 1,
});

// Claim the drop to the passed in account ID
await claim({
secretKey: secretKeys[0],
accountId: "benjiman.testnet"
})

Example

Creating a simple $NEAR drop and using it to create a brand new NEAR account:

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// create 2 keys with no entropy (all random). The first will be used for the drop and the second
// will be used as the full access key for the newly created account
const {publicKeys, secretKeys} = await generateKeys({
numKeys: 2
});

// Create a simple drop with 1 $NEAR
await createDrop({
publicKeys: [publicKeys[0]],
depositPerUseNEAR: 1,
});

// Claim the drop and create a new account
await claim({
secretKey: secretKeys[0],
newAccountId: "my-newly-creating-account.testnet",
newPublicKey: publicKeys[1]
})

Example

Creating a drop and adding a password to it. Generate the password using the hash function and pass it into claim the drop:

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

const basePassword = "my-cool-password123";
// Create a simple drop with 1 $NEAR and pass in a base password to create a unique password for each use of each key
const {keys} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1,
basePassword
});

// Create the password to pass into claim which is a hash of the basePassword, public key and whichever use we are on
let currentUse = 1;
let passwordForClaim = await hashPassword(basePassword + keys.publicKeys[0] + currentUse.toString());

// Claim the drop to the passed in account ID and use the password we generated above.
await claim({
secretKey: keys.secretKeys[0],
accountId: "benjiman.testnet",
password: passwordForClaim
})

Parameters

NameTypeDescription
«destructured»Object-
› accountId?stringThe account ID of an existing account that will be used to claim the drop.
› fcArgs?string[]For FC drops, if user_args_rule is set by the funder, when claiming, custom arguments can be passed into the function. The number of args in the array need to match the number of methods being executed.
› newAccountId?stringIf passed in, a new account ID will be created and the drop will be claimed to that account. This must be an account that does not exist yet.
› newPublicKey?stringIf creating a new account, a public key must be passed in to be used as the full access key for the newly created account.
› password?stringIf a password is required to use the key, it can be passed in
› secretKeystringThe private key associated with the Keypom link. This can either contain the ed25519: prefix or not.

Returns

Promise<any>

Defined in

lib/claims.ts:108


createDrop

createDrop(«destructured»): Promise<CreateOrAddReturn>

Creates a new drop based on parameters passed in. This drop can have keys that are manually generated and passed in, or automatically generated. If they're automatically generated, they can be based off a set of entropy. For NFT and FT drops, assets can automatically be sent to Keypom to register keys as part of the payload. The deposit is estimated based on parameters that are passed in and the transaction can be returned instead of signed and sent to the network. This can allow you to get the required deposit from the return value and use that to fund the account's Keypom balance to avoid multiple transactions being signed in the case of a drop with many keys.

Example

Create a basic simple drop containing 10 keys each with 1 $NEAR. Each key is completely random:

// Initialize the SDK for the given network and NEAR connection. No entropy passed in so any auto generated keys will
// be completely random unless otherwise overwritten.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with 10 completely random keys. The return value `keys` contains information about the generated keys
const {keys} = await createDrop({
numKeys: 10,
depositPerUseNEAR: 1,
});

console.log('public keys: ', keys.publicKeys);
console.log('private keys: ', keys.secretKeys);

Example

Init funder with root entropy and generate deterministic keys for a drop. Compare with manually generated keys:

// Initialize the SDK for the given network and NEAR connection. Root entropy is passed into the funder account so any generated keys
// Will be based off that entropy.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1",
rootEntropy: "my-global-secret-password"
}
});

// Create a simple drop with 5 keys. Each key will be derived based on the rootEntropy of the funder, the drop ID, and key nonce.
const { keys: keysFromDrop, dropId } = await createDrop({
numKeys: 5,
depositPerUseNEAR: 1,
});

// Deterministically Generate the Private Keys:
const nonceDropIdMeta = Array.from({length: 5}, (_, i) => `${dropId}_${i}`);
const manualKeys = await generateKeys({
numKeys: 5,
rootEntropy: "my-global-secret-password",
metaEntropy: nonceDropIdMeta
})

// Get the public and private keys from the keys generated by the drop
const {publicKeys, secretKeys} = keysFromDrop;
// Get the public and private keys from the keys that were manually generated
const {publicKeys: pubKeysGenerated, secretKeys: secretKeysGenerated} = manualKeys;
// These should match!
console.log('secretKeys: ', secretKeys)
console.log('secretKeysGenerated: ', secretKeysGenerated)

// These should match!
console.log('publicKeys: ', publicKeys)
console.log('pubKeysGenerated: ', pubKeysGenerated)

Example

Use manually generated keys to create a drop:

// Initialize the SDK for the given network and NEAR connection. No entropy passed in so any auto generated keys will
// be completely random unless otherwise overwritten.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Generate 10 random keys
const {publicKeys} = await generateKeys({
numKeys: 10
});

// Create a drop using the keys that were generated. Since keys are passed in, the return value won't contain information about the keys.
await createDrop({
publicKeys,
depositPerUseNEAR: 1,
});

Example

Create a simple drop with 1 key and 1 use per key. This 1 use-key should be password protected based on a base-password:

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

const basePassword = "my-cool-password123";
// Create a simple drop with 1 $NEAR and pass in a base password to create a unique password for each use of each key
const {keys} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1,
basePassword
});

// Create the password to pass into claim which is a hash of the basePassword, public key and whichever use we are on
let currentUse = 1;
let passwordForClaim = await hashPassword(basePassword + keys.publicKeys[0] + currentUse.toString());

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› basePassword?stringFor doing password protected drops, this is the base password that will be used to generate all the passwords. It will be double hashed with the public keys. If specified, by default, all key uses will have their own unique password unless passwordProtectedUses is passed in.
› config?DropConfigAllows specific drop behaviors to be configured such as the number of uses each key / link will have.
› depositPerUseNEAR?string | numberHow much $NEAR should be contained in each link. Unit in $NEAR (i.e 1 = 1 $NEAR)
› depositPerUseYocto?stringHow much $yoctoNEAR should be contained in each link. Unit in yoctoNEAR (1 yoctoNEAR = 1e-24 $NEAR)
› dropId?stringSpecify a custom drop ID rather than using the incrementing nonce on the contract.
› fcData?FCDataFor creating a function call drop, this contains necessary configurable information about the drop.
› ftData?FTDataFor creating a fungible token drop, this contains necessary configurable information about the drop.
› metadata?stringString of metadata to attach to the drop. This can be whatever you would like and is optional. Often this is stringified JSON.
› nftData?NFTDataFor creating a non-fungible token drop, this contains necessary configurable information about the drop.
› numKeys?numberSpecify how many keys should be generated for the drop. If the funder has rootEntropy set OR rootEntropy is passed in, the keys will be deterministically generated using the drop ID, key nonce, and entropy. Otherwise, each key will be generated randomly. If this is not passed in, the publicKeys parameter must be passed in.
› passwordProtectedUses?number[]For doing password protected drops, specifies exactly which uses will be password protected. The uses are NOT zero indexed (i.e 1st use = 1). Each use will have a different, unique password generated via double hashing the base password + public key + key use.
› publicKeys?string[]Pass in a custom set of publicKeys to add to the drop. If this is not passed in, keys will be generated based on the numKeys parameter.
› requiredGas?stringAllows you to overload how much gas should be attached to the transaction when the key is claimed. This should be in Gas units (1 TGas = 1000000000000). By default, 100 TGas is attached.
› returnTransactions?booleanIf true, the transaction will be returned instead of being signed and sent. This is useful for getting the requiredDeposit from the return value without actually signing the transaction.
› rootEntropy?stringSpecify an entropy to use for generating keys (will overload the funder's rootEntropy if applicable). This parameter only matters if the publicKeys variable is not passed in.
› simpleData?SimpleDataFor creating a simple drop, this contains necessary configurable information about the drop.
› successUrl?stringWhen signing with a wallet, a success URl can be included that the user will be redirected to once the transaction has been successfully signed.
› useBalance?booleanIf the account has a balance within the Keypom contract, set this to true to avoid the need to attach a deposit. If the account doesn't have enough balance, an error will throw.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<CreateOrAddReturn>

Object containing: the drop ID, the responses of the execution, as well as any auto generated keys (if any).

Defined in

lib/drops.ts:176

User Balance Functions

addToBalance

addToBalance(«destructured»): Promise<any>

Deposit some amount of $NEAR or yoctoNEAR$ into the Keypom contract. This amount can then be used to create drops or add keys without Having to explicitly attach a deposit every time. It can be thought of like a bank account.

Example

Add 1 $NEAR to the account balance

// Initialize the SDK on testnet
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

await addToBalance({
amount: "1",
)};

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› amountNear?stringHuman readable format for the amount of tokens to add. Example ts Example: transferring one $NEAR should be passed in as "1" and NOT "1000000000000000000000000"
› amountYocto?stringAmount of tokens to add but considering the decimal amount (non human-readable). Example ts Transferring one $NEAR should be passed in as "1000000000000000000000000" and NOT "1"
› successUrl?stringWhen signing with a wallet, a success URl can be included that the user will be redirected to once the transaction has been successfully signed.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<any>

Defined in

lib/balances.ts:37


withdrawBalance

withdrawBalance(«destructured»): Promise<any>

Withdraw all the $NEAR from your balance in the Keypom contract.

Example

Add 1 $NEAR to the account balance and then withdraw it

// Initialize the SDK on testnet
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

await addToBalance({
amount: "1",
});

await withdrawBalance({});

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<any>

Defined in

lib/balances.ts:118

Public Sale Functions

addToSaleAllowlist

addToSaleAllowlist(«destructured»): Promise<any>

Add a list of account IDs to a drop's sale allowlist. If the allowlist is empty, anyone can purchase keys. The sale object must exist in the drop's config for this to go through.

Example

const {dropId} = await createDrop({
numKeys: 0,
depositPerUseNEAR: 0.1,
config: {
sale: {
maxNumKeys: 2,
pricePerKeyNEAR: 1
}
}
});

let canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, true);

await addToSaleAllowlist({dropId, accountIds: ["barfoo.testnet"]});
canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, false);

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› accountIdsstring[]A list of account IDs that should be added to the sale allowlist
› dropIdstringThe drop ID for the drop
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<any>

Defined in

lib/sales.ts:44


addToSaleBlocklist

addToSaleBlocklist(«destructured»): Promise<any>

Add a list of account IDs to a drop's sale blocklist. The sale object must exist in the drop's config for this to go through.

Example

    const {dropId} = await createDrop({
numKeys: 0,
depositPerUseNEAR: 0.1,
config: {
sale: {
maxNumKeys: 2,
pricePerKeyNEAR: 1
}
}
});

let canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, true);

await addToSaleBlocklist({dropId, accountIds: ["foobar.testnet"]});
canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, false);

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› accountIdsstring[]A list of account IDs that should be added to the sale blocklist
› dropIdstringThe drop ID for the drop
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<any>

Defined in

lib/sales.ts:224


removeFromSaleAllowlist

removeFromSaleAllowlist(«destructured»): Promise<any>

Remove a list of account IDs from a drop's sale allowlist. If the allowlist is empty, anyone can purchase keys. The sale object must exist in the drop's config for this to go through.

Example

    const {dropId} = await createDrop({
numKeys: 0,
depositPerUseNEAR: 0.1,
config: {
sale: {
maxNumKeys: 2,
pricePerKeyNEAR: 1,
allowlist: ["foobar.testnet", "barfoo.testnet"]
}
}
});

let canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, true);

canAddKeys = await canUserAddKeys({dropId, accountId: "not_in_allowlist.testnet"});
t.is(canAddKeys, false);

await removeFromSaleAllowlist({dropId, accountIds: ["foobar.testnet"]});
canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, false);

await removeFromSaleAllowlist({dropId, accountIds: ["barfoo.testnet"]});
canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, true);

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› accountIdsstring[]A list of account IDs that should be removed from the sale's allowlist
› dropIdstringThe drop ID for the drop
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<any>

Defined in

lib/sales.ts:138


removeFromSaleBlocklist

removeFromSaleBlocklist(«destructured»): Promise<any>

Remove a list of account IDs from a drop's sale blocklist. The sale object must exist in the drop's config for this to go through.

Example

    const {dropId} = await createDrop({
numKeys: 0,
depositPerUseNEAR: 0.1,
config: {
sale: {
maxNumKeys: 2,
pricePerKeyNEAR: 1,
blocklist: ["foobar.testnet"]
}
}
});

let canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, false);

canAddKeys = await canUserAddKeys({dropId, accountId: "not_in_blocklist.testnet"});
t.is(canAddKeys, true);

await removeFromSaleBlocklist({dropId, accountIds: ["foobar.testnet"]});
canAddKeys = await canUserAddKeys({dropId, accountId: "foobar.testnet"});
t.is(canAddKeys, true);

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› accountIdsstring[]A list of account IDs that should be removed from the sale's allowlist
› dropIdstringThe drop ID for the drop
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<any>

Defined in

lib/sales.ts:314


updateSale

updateSale(«destructured»): Promise<any>

Remove a list of account IDs from a drop's sale blocklist. The sale object must exist in the drop's config for this to go through.

Example

    const {dropId} = await createDrop({
numKeys: 0,
depositPerUseNEAR: 0.1,
config: {
sale: {
maxNumKeys: 2,
pricePerKeyNEAR: 1
}
}
});

await updateSale({
dropId,
pricePerKeyNEAR: 2
})

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› autoWithdrawFunds?booleanShould the revenue generated be sent to the funder's account balance or automatically withdrawn and sent to their NEAR wallet?
› dropIdstringThe drop ID for the drop
› end?numberBlock timestamp dictating the end of the public sale. If None, keys can be added indefinitely Measured in number of non-leap-nanoseconds since January 1, 1970 0:00:00 UTC.
› maxNumKeys?numberMaximum number of keys that can be added to this drop. If None, there is no max.
› pricePerKeyNEAR?numberAmount of $NEAR that the user needs to attach (if they are not the funder) on top of costs. This amount will be Automatically sent to the funder's balance. If None, the keys are free to the public.
› pricePerKeyYocto?string-
› start?numberMinimum block timestamp before the public sale starts. If None, keys can be added immediately Measured in number of non-leap-nanoseconds since January 1, 1970 0:00:00 UTC.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<any>

Defined in

lib/sales.ts:399

Trial Accounts

canExitTrial

canExitTrial(«destructured»): Promise<boolean>

Check whether a trial account is able to exit their trial state and become a fully fledged normal account.

Example

Create a trial account and check whether it can immediately exit

    await initKeypom({
// near,
network: 'testnet',
funder: {
accountId: fundingAccountId,
secretKey: fundingAccountSecretKey,
}
});

const callableContracts = [
`nft.examples.testnet`
]

const {dropId, keys: {secretKeys: trialSecretKeys, publicKeys: trialPublicKeys}}
= await createTrialAccountDrop({
numKeys: 1,
contractBytes: [...readFileSync('./test/ext-wasm/trial-accounts.wasm')],
startingBalanceNEAR: 0.5,
callableContracts: callableContracts,
callableMethods: ['*'],
maxAttachableNEARPerContract: [1],
trialEndFloorNEAR: 0.33 + 0.3
})

const desiredAccountId = `${dropId}-keypom.testnet`
const trialSecretKey = trialSecretKeys[0]
await claimTrialAccountDrop({
desiredAccountId,
secretKey: trialSecretKey
})

const canExitTrial = await keypom.canExitTrial({
trialAccountId: desiredAccountId
})
console.log('canExitTrial: ', canExitTrial)
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `«destructured»` | `Object` | - |
| › `trialAccountId` | `string` | The account ID of the trial account |

#### Returns

`Promise`<`boolean`\>

#### Defined in

[lib/trial-accounts/trial-active.ts:403](https://github.com/keypom/keypom-js/blob/9a866ee41/packages/core/src/lib/trial-accounts/trial-active.ts#L403)

___

### claimTrialAccountDrop

**claimTrialAccountDrop**(`«destructured»`): `Promise`<`any`\>

Claim a Keypom trial account drop which will create a new account, deploy and initialize the trial account contract, and setup the account with initial conditions as specified in the drop.

**`Example`**

Creating a trial account with any callable methods, an amount of 0.5 $NEAR and 5 keys.
```js
const callableContracts = [
`v1.social08.testnet`,
'guest-book.examples.keypom.testnet',
]

const {dropId, keys: {secretKeys: trialSecretKeys, publicKeys: trialPublicKeys}}
= await createTrialAccountDrop({
numKeys: 1,
contractBytes: [...readFileSync('./test/ext-wasm/trial-accounts.wasm')],
startingBalanceNEAR: 0.5,
callableContracts: callableContracts,
callableMethods: ['set:grant_write_permission', '*'],
maxAttachableNEARPerContract: callableContracts.map(() => '1'),
trialEndFloorNEAR: 0.33
})

const newAccountId = `${Date.now().toString()}.linkdrop-beta.keypom.testnet`
await claimTrialAccountDrop({
secretKey: trialSecretKeys[0],
desiredAccountId: newAccountId,
})

console.log(`

${JSON.stringify({
account_id: newAccountId,
public_key: trialPublicKeys[0],
private_key: trialSecretKeys[0]
})}

`)

console.log(`http://localhost:1234/keypom-url/${newAccountId}#${trialSecretKeys[0]}`)

Parameters

NameTypeDescription
«destructured»Object-
› desiredAccountIdstringThe account ID that will be created for the trial
› secretKeystringThe private key associated with the Keypom link. This can either contain the ed25519: prefix or not.

Returns

Promise<any>

Defined in

lib/trial-accounts/pre-trial.ts:505


createTrialAccountDrop

createTrialAccountDrop(«destructured»): Promise<CreateOrAddReturn>

Creates a new trial account drop which can be used to instantly sign users into decentralized applications that support the Keypom wallet selector plugin.

The trial account is locked into certain behaviors depending on what is passed into createTrialAccountDrop. These behaviors include callable contracts, methods on those contracts, the maximum amount of $NEAR that can be spent on each contract as well as an exit condition. Once the trial account has run out of funds, the only way to retain any assets from the trial or continue using the account ID, is to repay the specific account ID for the amount of $NEAR specified.

Example

Creating a trial account with any callable methods, an amount of 0.5 $NEAR and 5 keys.

const {keys: {secretKeys: trialSecretKeys, publicKeys: trialPublicKeys}} = await createTrialAccountDrop({
contractBytes: [...readFileSync('./test/ext-wasm/trial-accounts.wasm')],
trialFundsNEAR: 0.5,
callableContracts: ['dev-1676298343226-57701595703433'],
callableMethods: ['*'],
amounts: ['0.5'],
numKeys: 5,
config: {
dropRoot: "linkdrop-beta.keypom.testnet"
}
})

const newAccountId = `${Date.now().toString()}.linkdrop-beta.keypom.testnet`
await claimTrialAccountDrop({
secretKey: trialSecretKeys[0],
desiredAccountId: newAccountId,
})

console.log(`

${JSON.stringify({
account_id: newAccountId,
public_key: trialPublicKeys[0],
private_key: trialSecretKeys[0]
})}

`)

console.log(`http://localhost:1234/keypom-url/${newAccountId}#${trialSecretKeys[0]}`)

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› callableContractsstring[]The contracts that the trial account should be able to call.
› callableMethodsstring[][]An array that contains the list of methods that the trial account should be able to call on each respective contract. To allow any methods to be called on the receiver contract, pass in [*].
› config?DropConfigAllows specific drop behaviors to be configured such as the number of uses each key / link will have.
› contractBytesnumber[]Bytes of the trial account smart contract
› dropId?stringSpecify a custom drop ID rather than using the incrementing nonce on the contract.
› maxAttachableNEARPerContract(string | number)[]The upper bound of $NEAR that trial account is able to attach to calls associated with each contract passed in. For no upper limit, pass in *. Units are in $NEAR (i.e 1 = 1 $NEAR).
› maxAttachableYoctoPerContractstring[]The upper bound of $yocto that trial account is able to attach to calls associated with each contract passed in. For no upper limit, pass in *. Units are in $yoctoNEAR (i.e 1 = 1 $yoctoNEAR).
› metadata?stringString of metadata to attach to the drop. This can be whatever you would like and is optional. Often this is stringified JSON.
› numKeysnumberSpecify how many keys should be generated for the drop. If the funder has rootEntropy set OR rootEntropy is passed in, the keys will be deterministically generated using the drop ID, key nonce, and entropy. Otherwise, each key will be generated randomly.
› publicKeys?string[]Pass in a custom set of publicKeys to add to the drop. If this is not passed in, keys will be generated based on the numKeys parameter.
› repayAmountNEAR?string | numberHow much $NEAR should be paid back to the specified funder in order to unlock the trial account. Unit in $NEAR (i.e 1 = 1 $NEAR)
› repayAmountYocto?stringHow much $NEAR should be paid back to the specified funder in order to unlock the trial account. Unit in yoctoNEAR (1 yoctoNEAR = 1e-24 $NEAR)
› repayTo?stringThe account that should receive the repayment of the trial account. If not specified, the drop funder will be used.
› returnTransactions?booleanIf true, the transaction will be returned instead of being signed and sent. This is useful for getting the requiredDeposit from the return value without actually signing the transaction.
› rootEntropy?stringSpecify an entropy to use for generating keys (will overload the funder's rootEntropy if applicable). This parameter only matters if the publicKeys variable is not passed in.
› startingBalanceNEAR?string | numberHow much $NEAR should the trial account start with? Unit in $NEAR (i.e 1 = 1 $NEAR)
› startingBalanceYocto?stringHow much $NEAR should the trial account start with? Unit in yoctoNEAR (1 yoctoNEAR = 1e-24 $NEAR)
› successUrl?stringWhen signing with a wallet, a success URl can be included that the user will be redirected to once the transaction has been successfully signed.
› trialEndFloorNEARstring | numberOnce the account has spent more than this amount (in $NEAR), the trial is over and the exit conditions must be met.
› trialEndFloorYoctostringOnce the account has spent more than this amount (in yocto), the trial is over and the exit conditions must be met.
› useBalance?booleanIf the account has a balance within the Keypom contract, set this to true to avoid the need to attach a deposit. If the account doesn't have enough balance, an error will throw.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<CreateOrAddReturn>

Object containing: the drop ID, the responses of the execution, as well as any auto generated keys (if any).

Defined in

lib/trial-accounts/pre-trial.ts:81


trialCallMethod

trialCallMethod(«destructured»): Promise<FinalExecutionOutcome[]>

Execute a method using a trial account. If the trial account is in the exit state, this will throw an error. Similarly, if the given method data cannot be executed by the trial account (e.g. the attached deposit exceeds the trial account's restrictions), this will throw an error.

Example

Using a trial account to mint a new NFT:

    await initKeypom({
network: 'testnet',
funder: {
accountId: fundingAccountId,
secretKey: fundingAccountSecretKey,
}
});

const callableContracts = [
`nft.examples.testnet`
]

const {dropId, keys: {secretKeys: trialSecretKeys, publicKeys: trialPublicKeys}}
= await createTrialAccountDrop({
numKeys: 1,
contractBytes: [...readFileSync('./test/ext-wasm/trial-accounts.wasm')],
startingBalanceNEAR: 0.5,
callableContracts: callableContracts,
callableMethods: ['*'],
maxAttachableNEARPerContract: [1],
trialEndFloorNEAR: 0.33 + 0.3
})

const desiredAccountId = `${dropId}-keypom.testnet`
const trialSecretKey = trialSecretKeys[0]
await claimTrialAccountDrop({
desiredAccountId,
secretKey: trialSecretKeys[0],
})

console.log('desiredAccountId: ', desiredAccountId)
console.log(`trialSecretKey: ${JSON.stringify(trialSecretKey)}`)

await trialCallMethod({
trialAccountId: desiredAccountId,
trialAccountSecretKey: trialSecretKey,
contractId: callableContracts[0],
methodName: 'nft_mint',
args: {
token_id: 'asdkasldkjasdlkajsldajsldaskjd',
receiver_id: 'foo.testnet',
metadata: {
title: 'test',
description: 'test',
media: 'test',
}
},
attachedDeposit: parseNearAmount('0.1'),
attachedGas: '30000000000000',
})

Parameters

NameTypeDescription
«destructured»Object-
› argsObjectThe arguments to pass to the method
› attachedDepositstringThe amount of NEAR to attach to the transaction
› attachedGasstringThe amount of gas to attach to the transaction
› contractIdstringThe contract ID of the contract to call
› methodNamestringThe method name to call
› trialAccountIdstringThe account ID of the trial account
› trialAccountSecretKeystringThe secret key of the trial account

Returns

Promise<FinalExecutionOutcome[]>

The outcome of the transaction

Defined in

lib/trial-accounts/trial-active.ts:248


trialSignAndSendTxns

trialSignAndSendTxns(«destructured»): Promise<FinalExecutionOutcome[]>

Execute a transaction that can contain multiple actions using a trial account. If the trial account is in the exit state, this will throw an error. Similarly, if any action cannot be executed by the trial account (e.g. the attached deposit exceeds the trial account's restrictions), this will throw an error.

Example

Use a Trial Account to min2

await initKeypom({
// near,
network: 'testnet',
funder: {
accountId: fundingAccountId,
secretKey: fundingAccountSecretKey,
}
});

const callableContracts = [
`nft.examples.testnet`
]

const {dropId, keys: {secretKeys: trialSecretKeys, publicKeys: trialPublicKeys}}
= await createTrialAccountDrop({
numKeys: 1,
contractBytes: [...readFileSync('./test/ext-wasm/trial-accounts.wasm')],
startingBalanceNEAR: 0.5,
callableContracts: callableContracts,
callableMethods: ['*'],
maxAttachableNEARPerContract: [1],
trialEndFloorNEAR: 0.33 + 0.3
})

const desiredAccountId = `${dropId}-keypom.testnet`
const trialSecretKey = trialSecretKeys[0]
await claimTrialAccountDrop({
desiredAccountId,
secretKey: trialSecretKeys[0],
})

console.log('desiredAccountId: ', desiredAccountId)
console.log(`trialSecretKey: ${JSON.stringify(trialSecretKey)}`)
const txns = [{
receiverId: callableContracts[0],
actions: [
{
type: 'FunctionCall',
params: {
methodName: 'nft_mint',
args: {
token_id: 'tokenId-keypom-1',
receiver_id: 'foo.testnet',
metadata: {
title: 'test1',
description: 'test1',
media: 'test1',
}
},
gas: '30000000000000',
deposit: parseNearAmount('0.1')
},
},
{
type: 'FunctionCall',
params: {
methodName: 'nft_mint',
args: {
token_id: 'tokenId-keypom-2',
receiver_id: 'foo.testnet',
metadata: {
title: 'test2',
description: 'test2',
media: 'test2',
}
},
gas: '30000000000000',
deposit: parseNearAmount('0.1')
},
},
],
}];

await trialSignAndSendTxns({
trialAccountId: desiredAccountId,
trialAccountSecretKey: trialSecretKey,
txns
})

Parameters

NameTypeDescription
«destructured»Object-
› trialAccountIdstringThe trial account ID to use
› trialAccountSecretKeystringThe trial account secret key to use
› txnsTransaction[]The transactions to execute

Returns

Promise<FinalExecutionOutcome[]>

The outcomes of the transactions

Defined in

lib/trial-accounts/trial-active.ts:106

View Functions

canUserAddKeys

canUserAddKeys(«destructured»): Promise<boolean>

Check if a given user can add keys to a drop. The only case where a user other than the funder could add keys is if the drop has a public sale running.

Example

await createDrop({
numKeys: 0,
depositPerUseNEAR: 0,
config: {
sale: {
maxNumKeys: 2,
pricePerKeyNEAR: 1
}
}
});

const canAddKeys = await canUserAddKeys({accountId: "foobar.testnet"});
t.is(canAddKeys, true);

Parameters

NameType
«destructured»Object
› accountIdstring
› dropIdstring

Returns

Promise<boolean>

Whether or not the user can add keys to the drop

Defined in

lib/views.ts:854


getContractSourceMetadata

getContractSourceMetadata(): Promise<ContractSourceMetadata>

Returns the source metadata for the Keypom contract that the SDK has been initialized on. This includes valuable information such as which specific version the contract is on and link to exactly which GitHub commit is deployed.

Example

Query for the current Keypom contract's source metadata:

// Initialize the SDK on testnet. No funder is passed in since we're only doing view calls.
await initKeypom({
network: "testnet",
});

// Query for the Keypom contract's source metadata
const metadata = await getContractSourceMetadata();

console.log('metadata: ', metadata)

Returns

Promise<ContractSourceMetadata>

The contract's source metadata

Defined in

lib/views.ts:896


getCurMethodData

getCurMethodData(«destructured»): Promise<ProtocolReturnedMethod[]>

Query for the current method data for a given key. This pertains to FC drops and the current method data is either null or an array of methods that will be invoked when the key is claimed next.

Example

const fcData = {
methods: [
null,
[
{
methodName: "nft_token",
receiverId: "nft.examples.testnet",
args: JSON.stringify({
token_id: "1"
}),
attachedDeposit: "0"
},
{
methodName: "nft_token",
receiverId: "nft.examples.testnet",
args: JSON.stringify({
token_id: "2"
}),
attachedDeposit: "0"
}
],
null
]
}

const {keys: {publicKeys, secretKeys}} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 0,
fcData,
config: {
usesPerKey: 3
}
});
const secretKey = secretKeys[0];

let curMethodData = await getCurMethodData({secretKey});
console.log('curMethodData (first): ', curMethodData)
t.is(curMethodData, null);

curMethodData = await getCurMethodData({secretKey, keyUse: 1});
t.is(curMethodData, null);
curMethodData = await getCurMethodData({secretKey, keyUse: 2});
t.true(curMethodData != null);
curMethodData = await getCurMethodData({secretKey, keyUse: 3});
t.is(curMethodData, null);

await claim({secretKey, accountId: 'foobar'})
curMethodData = await getCurMethodData({secretKey});
t.true(curMethodData != null);

await claim({secretKey, accountId: 'foobar'})
curMethodData = await getCurMethodData({secretKey});
console.log('curMethodData (third): ', curMethodData)
t.is(curMethodData, null);

Parameters

NameType
«destructured»Object
› keyUse?number
› publicKey?string
› secretKey?string

Returns

Promise<ProtocolReturnedMethod[]>

The current method data for the key

Defined in

lib/views.ts:797


getDropInformation

getDropInformation(«destructured»): Promise<ProtocolReturnedDrop>

Get information about a specific drop by passing in either a drop ID, public key, or secret key.

Example

Create a simple drop and retrieve information about it:

// Initialize the SDK on testnet.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with 1 key automatically created. That key will be completely random since there is no entropy.
const {dropId} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1
});

// Query for the drop information and also return the key information as well
const dropInfo = await getDropInformation({
dropId,
withKeys: true
})

console.log('dropInfo: ', dropInfo)

Example

Create a simple drop and get the drop information based on a public key and then the secret key:

// Initialize the SDK on testnet.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with 1 key automatically created. That key will be completely random since there is no entropy.
const {keys} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1
});

// Query for the drop information and also return the key information as well
let dropInfo = await getDropInformation({
publicKey: keys.publicKeys[0],
withKeys: true
})

console.log('dropInfo via public key: ', dropInfo)

// Query for the drop information and also return the key information as well
dropInfo = await getDropInformation({
secretKey: keys.secretKeys[0],
withKeys: true
})

console.log('dropInfo via secret key: ', dropInfo)

Parameters

NameType
«destructured»Object
› dropId?string
› publicKey?string
› secretKey?string
› withKeys?boolean

Returns

Promise<ProtocolReturnedDrop>

Drop information which may or may not have a keys field of type KeyInfo depending on if withKeys is specified as true.

Defined in

lib/views.ts:336


getDropSupplyForOwner

getDropSupplyForOwner(accountId): Promise<number>

Returns the total supply of active drops for a given account ID

Example

Create a drop and check how many the owner has:

// Initialize the SDK on testnet.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with no keys
await createDrop({
depositPerUseNEAR: 1
});

// Query for the amount of drops owned by the account
const dropSupply = await getDropSupplyForOwner({
accountId: "benji_demo.testnet"
})

console.log('dropSupply: ', dropSupply)

Parameters

NameTypeDescription
accountIdObjectThe account that the drops belong to.
accountId.accountIdstring-

Returns

Promise<number>

Amount of drops

Defined in

lib/views.ts:517


getDrops

getDrops(«destructured»): Promise<ProtocolReturnedDrop[]>

Paginate through drops owned by an account. If specified, information for the first 50 keys in each drop can be returned as well.

Example

Get drop information for the last 5 drops owned by a given account:

// Initialize the SDK on testnet. No funder is passed in since we're only doing view calls.
await initKeypom({
network: "testnet",
});

// Get the number of drops the account has.
const numDrops = await getDropSupply({
accountId: "benjiman.testnet"
});

// Query for drop information for the last 5 drops and their respective keys
const dropsAndKeys = await getDrops({
accountId: "benjiman.testnet",
start: numDrops - 5,
withKeys: true
})

console.log('dropsAndKeys: ', dropsAndKeys)

Parameters

NameTypeDescription
«destructured»Object-
› accountIdstringThe funding account that the drops belong to.
› limitnumberHow many drops to paginate through.
› startstring | numberWhere to start paginating through drops.
› withKeysbooleanWhether or not to include key information for the first 50 keys in each drop.

Returns

Promise<ProtocolReturnedDrop[]>

Defined in

lib/views.ts:562


getKeyBalance

getKeyBalance(«destructured»): Promise<string>

Returns the balance associated a with given public key. If only the secret key is known, this can be passed in instead. This is used by the NEAR wallet to display the amount of the linkdrop

Example

Create a 1 $NEAR linkdrop and query for its balance:

// Initialize the SDK on testnet.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with 1 key automatically created. That key will be completely random since there is no entropy.
const {keys} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1
});

// Query for the amount of yoctoNEAR contained within the key
const keyBalance = await getKeyBalance({
publicKey: keys.publicKeys[0]
})

console.log('keyBalance: ', keyBalance)

Parameters

NameType
«destructured»Object
› publicKey?string
› secretKey?string

Returns

Promise<string>

The amount of yoctoNEAR that is contained within the key

Defined in

lib/views.ts:47


getKeyInformation

getKeyInformation(«destructured»): Promise<ProtocolReturnedKeyInfo>

Returns the KeyInfo corresponding to a specific public key

Example

Create a drop and query for the key information:

// Initialize the SDK on testnet.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with 1 key automatically created. That key will be completely random since there is no entropy.
const {keys} = await createDrop({
numKeys: 1,
depositPerUseNEAR: 1
});

// Query for the key information for the key that was created
const keyInfo = await getKeyInformation({
publicKey: keys.publicKeys[0]
})

console.log('keyInfo: ', keyInfo)

Parameters

NameType
«destructured»Object
› publicKey?string
› secretKey?string

Returns

Promise<ProtocolReturnedKeyInfo>

Key information struct for that specific key.

Defined in

lib/views.ts:177


getKeyInformationBatch

getKeyInformationBatch(«destructured»): Promise<ProtocolReturnedKeyInfo[]>

Returns a vector of KeyInfo corresponding to a set of public keys passed in.

Example

Create a drop and query for the key information for all keys created:

// Initialize the SDK on testnet.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with 5 keys automatically created. That key will be completely random since there is no entropy.
const {keys} = await createDrop({
numKeys: 5,
depositPerUseNEAR: 1
});

// Query for the key information for the key that was created
const keyInfos = await getKeyInformationBatch({
publicKeys: keys.publicKeys
})

console.log('keyInfos: ', keyInfos)

Parameters

NameType
«destructured»Object
› publicKeys?string[]
› secretKeys?string[]

Returns

Promise<ProtocolReturnedKeyInfo[]>

Array of Key information structs for the keys passed in

Defined in

lib/views.ts:236


getKeySupplyForDrop

getKeySupplyForDrop(dropId): Promise<number>

Returns the total supply of active keys for a given drop

Example

Create a drop with 5 keys and query for the key supply:

// Initialize the SDK on testnet.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with 5 keys automatically created. That key will be completely random since there is no entropy.
const {keys, dropId} = await createDrop({
numKeys: 5,
depositPerUseNEAR: 1
});

// Query for the key supply for the drop that was created
const keySupply = await getKeySupplyForDrop({
dropId
})

console.log('keySupply: ', keySupply)

Parameters

NameTypeDescription
dropIdObjectThe drop ID for the specific drop that you want to get information about.
dropId.dropIdstring-

Returns

Promise<number>

Number of active keys

Defined in

lib/views.ts:416


getKeyTotalSupply

getKeyTotalSupply(): Promise<number>

Query for the total supply of keys currently on the Keypom contract

Example

Query for the key supply on the v1.keypom.testnet contract:

// Initialize the SDK on testnet. No funder is passed in since we're only doing view calls
await initKeypom({
network: "testnet",
keypomContractId: "v1.keypom.testnet"
});

// Query for the number of keys on the contract
const numKeys = await getKeyTotalSupply();

console.log('numKeys: ', numKeys)

Returns

Promise<number>

The amount of keys.

Defined in

lib/views.ts:92


getKeys

getKeys(«destructured»): Promise<ProtocolReturnedKeyInfo[]>

Paginate through all active keys on the contract and return a vector of key info.

Example

Query for first 50 keys on the v1.keypom.testnet contract:

// Initialize the SDK on testnet. No funder is passed in since we're only doing view calls
await initKeypom({
network: "testnet",
keypomContractId: "v1.keypom.testnet"
});

// Query for the first 50 keys on the contract
const keyInfo = await getKeys({
start: 0,
limit: 50
});

console.log('keyInfo: ', keyInfo)

Parameters

NameTypeDescription
«destructured»Object-
› limit?number(OPTIONAL) How many keys to paginate through.
› start?string | number(OPTIONAL) Where to start paginating through keys.

Returns

Promise<ProtocolReturnedKeyInfo[]>

Vector of KeyInfo.

Defined in

lib/views.ts:126


getKeysForDrop

getKeysForDrop(«destructured»): Promise<ProtocolReturnedKeyInfo[]>

Paginate through all keys in a specific drop, returning an array of KeyInfo.

Example

Create a drop with 5 keys and return all the key info objects:

// Initialize the SDK on testnet.
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create a drop with 5 keys automatically created. That key will be completely random since there is no entropy.
const {dropId} = await createDrop({
numKeys: 5,
depositPerUseNEAR: 1
});

// Query for the key supply for the drop that was created
const keyInfos = await getKeysForDrop({
dropId
})

console.log('keyInfos: ', keyInfos)

Parameters

NameType
«destructured»Object
› dropIdstring
› limit?number
› start?string | number

Returns

Promise<ProtocolReturnedKeyInfo[]>

Vector of KeyInfo objects returned from pagination

Defined in

lib/views.ts:465


getNftSupplyForDrop

getNftSupplyForDrop(dropId): Promise<number>

Return the total supply of token IDs for a given NFT drop.

Example

Query for the supply of tokens on a specific drop:

// Initialize the SDK on testnet. No funder is passed in since we're only doing view calls.
await initKeypom({
network: "testnet",
});

// Query for the amount of token IDs on the drop
const tokenSupply = await getNftSupplyForDrop({
dropId: "1669840629120"
})

console.log('tokenSupply: ', tokenSupply)

Parameters

NameTypeDescription
dropIdObjectThe drop ID that the tokens belong to.
dropId.dropIdstring-

Returns

Promise<number>

The amount of token IDs on the drop

Defined in

lib/views.ts:634


getNftTokenIDsForDrop

getNftTokenIDsForDrop(«destructured»): Promise<string[]>

Paginate through token IDs in an NFT drop to return a vector of token IDs.

Example

Query for a list of token IDs on a specific drop:

// Initialize the SDK on testnet. No funder is passed in since we're only doing view calls.
await initKeypom({
network: "testnet",
});

// Query for a set of token IDs on the drop
const tokenList = await getNftTokenIDsForDrop({
dropId: "1669840629120"
})

console.log('tokenList: ', tokenList)

Parameters

NameType
«destructured»Object
› dropIdstring
› limit?number
› start?string | number

Returns

Promise<string[]>

Vector of token IDs

Defined in

lib/views.ts:673


getUserBalance

getUserBalance(accountId): Promise<string>

Query for a user's current balance on the Keypom contract

Example

Query for a user's current balance on the Keypom contract:

// Initialize the SDK on testnet. No funder is passed in since we're only doing view calls.
await initKeypom({
network: "testnet",
});

// Query for the drop information for a specific drop
const userBal = await getUserBalance({
accountId: "benjiman.testnet",
})

console.log('userBal: ', userBal)

Parameters

NameTypeDescription
accountIdObjectThe account ID of the user to retrieve the balance for.
accountId.accountIdstring-

Returns

Promise<string>

The user's current balance

Defined in

lib/views.ts:716

Functions

convertBasicTransaction

convertBasicTransaction(«destructured»): Promise<Transaction>

Parameters

NameType
«destructured»Object
› signerIdstring
› signerPkPublicKey
› txnInfoBasicTransaction

Returns

Promise<Transaction>

Defined in

lib/keypom-utils.ts:1445


isUnclaimedTrialDrop

isUnclaimedTrialDrop(«destructured»): Promise<boolean>

Parameters

NameType
«destructured»Object

Returns

Promise<boolean>

Defined in

lib/trial-accounts/utils.ts:232


wrapTxnParamsForTrial

wrapTxnParamsForTrial(params, newParams?): Object

Parameters

NameType
paramsany
newParamsObject

Returns

Object

Defined in

lib/trial-accounts/utils.ts:103

Deleting State

deleteDrops

deleteDrops(«destructured»): Promise<(void | FinalExecutionOutcome[])[][]>

Delete a set of drops and optionally withdraw any remaining balance you have on the Keypom contract.

Example

Create 5 drops and delete each of them:

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// loop to create 5 simple drops each with 5 more keys than the next
for(var i = 0; i < 5; i++) {
// create 10 keys with no entropy (all random)
const {publicKeys} = await generateKeys({
numKeys: 5 * (i+1) // First drop will have 5, then 10, then 15 etc..
});

// Create the simple
await createDrop({
publicKeys,
depositPerUseNEAR: 1,
});
}

let drops = await getDrops({accountId: "benji_demo.testnet"});
console.log('drops: ', drops)

await deleteDrops({
drops
})

// Get the number of drops the account has after deletion (should be zero)
const numDrops = await getDropSupply({
accountId: "benjiman.testnet"
});
console.log('numDrops: ', numDrops)

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› dropIds?string[]Specify a set of drop IDs to delete.
› drops?ProtocolReturnedDrop[]If the set of drop information for the drops you want to delete (from getDropInformation or getDrops) is already known to the client, it can be passed in instead of the drop IDs to reduce computation.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.
› withdrawBalance?booleanWhether or not to withdraw any remaining balance on the Keypom contract.

Returns

Promise<(void | FinalExecutionOutcome[])[][]>

Defined in

lib/drops.ts:599


deleteKeys

deleteKeys(«destructured»): Promise<any>

Delete a set of keys from a drop and optionally withdraw any remaining balance you have on the Keypom contract.

Example

Create a drop with 5 keys and delete the first one:

// Initialize the SDK for the given network and NEAR connection
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

// Create the simple drop with 5 random keys
const {keys, dropId} = await createDrop({
numKeys: 5,
depositPerUseNEAR: 1,
});

await deleteKeys({
dropId,
publicKeys: keys.publicKeys[0] // Can be wrapped in an array as well
})

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› dropIdstringWhich drop ID do the keys belong to?
› publicKeysstring | string[]Specify a set of public keys to delete. If deleting a single publicKey, the string can be passed in without wrapping it in an array.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.
› withdrawBalance?booleanWhether or not to withdraw any remaining balance on the Keypom contract.

Returns

Promise<any>

Defined in

lib/keys.ts:441

Registering Key Uses

ftTransferCall

ftTransferCall(«destructured»): Promise<Transaction | Promise<void | FinalExecutionOutcome[]>>

For FT Drops, keys need to be registered before they can be used. This is done via the ft_transfer_call method on the FT contract. This is a convenience method to make that process easier.

Example

Send FTs using the funder account (not passing in any accounts into the call):

// Initialize the SDK on testnet
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

await ftTransferCall({
contractId: "ft.keypom.testnet",
amount: "1",
dropId: "1231231",
)};

Parameters

NameTypeDescription
«destructured»Object-
› absoluteAmount?stringAmount of tokens to transfer but considering the decimal amount (non human-readable). Example: transferring one wNEAR should be passed in as "1000000000000000000000000" and NOT "1"
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› amount?stringHuman readable format for the amount of tokens to transfer. Example: transferring one wNEAR should be passed in as "1" and NOT "1000000000000000000000000"
› contractIdstringThe fungible token contract ID.
› dropIdstringThe drop ID to register the keys for.
› returnTransaction?booleanIf true, the transaction will be returned instead of being signed and sent.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<Transaction | Promise<void | FinalExecutionOutcome[]>>

Defined in

lib/keypom-utils.ts:797


nftTransferCall

nftTransferCall(«destructured»): Promise<Transaction[] | (void | FinalExecutionOutcome[])[]>

For NFT Drops, keys need to be registered before they can be used. This is done via the nft_transfer_call method on the NFT contract. This is a convenience method to make that process easier.

Example

Send 3 NFTs using the funder account (not passing in any accounts into the call):

// Initialize the SDK on testnet
await initKeypom({
network: "testnet",
funder: {
accountId: "benji_demo.testnet",
secretKey: "ed25519:5yARProkcALbxaSQ66aYZMSBPWL9uPBmkoQGjV3oi2ddQDMh1teMAbz7jqNV9oVyMy7kZNREjYvWPqjcA6LW9Jb1"
}
});

await nftTransferCall({
contractId: "nft.keypom.testnet",
tokenIds: ["1", "2", "3],
dropId: "1231231",
)};

Parameters

NameTypeDescription
«destructured»Object-
› account?AccountAccount object that if passed in, will be used to sign the txn instead of the funder account.
› contractIdstringThe non-fungible token contract ID.
› dropIdstringThe drop ID to register the keys for.
› returnTransactions?booleanIf true, the transaction will be returned instead of being signed and sent.
› tokenIdsstring[]A set of token IDs that should be sent to the Keypom contract in order to register keys.
› wallet?AnyWalletIf using a browser wallet through wallet selector and that wallet should sign the transaction, pass in the object.

Returns

Promise<Transaction[] | (void | FinalExecutionOutcome[])[]>

Defined in

lib/keypom-utils.ts:906