Creating Passes
To create a pass, you will need to call the POST /v0/passes
with a signed message, and some related information.
Prerequisites
Before calling the POST /v0/passes
endpoint, it is necessary to first obtain a signature from the user's wallet.
This can be done through the use of any JSON RPC provider that has a connected wallet. Additionally, we have integrated solutions such as Crossmint and Magic Link for custodial wallet solutions. The following are examples of how to generate a signature:
Wagmi Example
Using the wagmi
useSigner React hook: View sample integration.
import { useSigner } from "wagmi";
export const Example = () => {
const { data: signer } = useSigner(); // NOTE: wallet must already be connected
const getSignature = async () => {
const signatureMessage = `Sign this message to generate a test pass with ethpass.xyz\n${Date.now()}`;
const signature = await signer.signMessage(signatureMessage);
// if successful, call /api/ethpass/create to create the pass
};
return <div>Your user interface here</div>;
};
Creating a Pass from an NFT
This process involves associating the NFT with a Pass, ensuring that the NFT's ownership is verified, and providing the necessary mechanisms for the seamless transfer and redemption of the associated benefits.
const payload = {
signature:
"0x71147d2b97a397061e6dbd82351867a7057bdb4d9566a8ac2d618e1a3e62d43c722245fb4e6a8e9ee814348bdd5c433224c8c10f9fadf7fd154b44c17056109f1c",
signatureMessage: "Sign this message to generate a pass with ethpass.xyz",
platform: "apple",
chain: {
name: "evm",
network: 1,
},
nft: {
contractAddress: "0x79c1d53f15e34895d608ff47ee56ad1f0f3f45d3",
tokenId: "443",
},
image: "https://ipfs.io/ipfs/QmYyXcVMgny4BJYiaUyTU46HX7seFNgnvte2eoL2fN2PXf",
};
const response = await fetch("https://api.ethpass.xyz/api/v0/passes", {
method: "POST",
body: JSON.stringify(payload),
headers: new Headers({
"content-type": "application/json",
"X-API-KEY": "YOUR_SECRET_API_KEY",
}),
});
Creating a pass from policies
Creating a Pass from policies allows you to define specific rules and conditions that must be met in order for a Pass to be issued or granted to a user. By leveraging policy-based Pass creation, you can establish customized criteria, such as membership eligibility, purchase requirements, or compliance regulations, to determine who is eligible to receive the Pass. This approach provides flexibility and control over Pass issuance, ensuring that it aligns with your desired parameters and objectives.
const payload = {
signature:
"0x71147d2b97a397061e6dbd82351867a7057bdb4d9566a8ac2d618e1a3e62d43c722245fb4e6a8e9ee814348bdd5c433224c8c10f9fadf7fd154b44c17056109f1c",
signatureMessage: "Sign this message to generate a pass with ethpass.xyz",
platform: "apple",
chain: {
name: "evm",
network: 1,
},
policies: [
"f0b2519c-df60-44bc-a611-dd18aacf5429",
"3d24bee6-e0f0-4426-8433-e575b230a7a6",
],
image: "https://ipfs.io/ipfs/QmYyXcVMgny4BJYiaUyTU46HX7seFNgnvte2eoL2fN2PXf",
};
const response = await fetch("https://api.ethpass.xyz/api/v0/passes", {
method: "POST",
body: JSON.stringify(payload),
headers: new Headers({
"content-type": "application/json",
"X-API-KEY": "YOUR_SECRET_API_KEY",
}),
});
Creating a pass from a wallet
Creating a Pass from a wallet without an NFT or policy allows you to provide benefits or access to users based on ownership of a specific wallet. This approach simplifies the process by not requiring the presence of an associated NFT or policy. Instead, users can authenticate their ownership of the wallet by providing a signature or other verification method.
By issuing a Pass linked to a user's wallet, you can offer various privileges, discounts, or exclusive services to wallet owners. This method is particularly useful when you want to provide personalized experiences or rewards to your loyal customers or members.
To create this type of Pass, follow a similar process as before, but exclude the nft
or policy
parameter. Instead, focus on verifying the wallet ownership through the signature obtained from the user. This way, you can seamlessly grant the Pass to wallet owners and ensure they receive the associated benefits effortlessly.
const payload = {
signature:
"0x71147d2b97a397061e6dbd82351867a7057bdb4d9566a8ac2d618e1a3e62d43c722245fb4e6a8e9ee814348bdd5c433224c8c10f9fadf7fd154b44c17056109f1c",
signatureMessage: "Sign this message to generate a pass with ethpass.xyz",
platform: "apple",
chain: {
name: "evm",
network: 1,
},
image: "https://ipfs.io/ipfs/QmYyXcVMgny4BJYiaUyTU46HX7seFNgnvte2eoL2fN2PXf",
};
const response = await fetch("https://api.ethpass.xyz/api/v0/passes", {
method: "POST",
body: JSON.stringify(payload),
headers: new Headers({
"content-type": "application/json",
"X-API-KEY": "YOUR_SECRET_API_KEY",
}),
});
Preventing the Creation of Duplicate Passes
The ethpass API is designed to be flexible and non-custodial, meaning it will not restrict the creation of passes with duplicate parameters. To avoid creating duplicate passes, it is recommended to implement a check in your creation process to check if a pass with the same parameters already exists.
You can find more details on how to do that here.