Skip to content

Instantly share code, notes, and snippets.

@julien51
Last active May 4, 2022 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julien51/ddb0e7edaace251a8acd7840fd9a371e to your computer and use it in GitHub Desktop.
Save julien51/ddb0e7edaace251a8acd7840fd9a371e to your computer and use it in GitHub Desktop.
// ABI for the Unlock contract (partial)
// You can also get it from the package '@unlock-protocol/contracts'
const UNLOCK_ABI = [
{
inputs: [
{
internalType: "bytes",
name: "data",
type: "bytes",
},
{
internalType: "uint16",
name: "_lockVersion",
type: "uint16",
},
],
name: "createUpgradeableLockAtVersion",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "nonpayable",
type: "function",
},
];
// ABI for the Lock contract (partial) for which you will deploy instances. I used the latest version (10) here.
// You can also get it from the package '@unlock-protocol/contracts'
const LOCK_ABI = [
{
inputs: [
{
internalType: "address payable",
name: "_lockCreator",
type: "address",
},
{
internalType: "uint256",
name: "_expirationDuration",
type: "uint256",
},
{ internalType: "address", name: "_tokenAddress", type: "address" },
{ internalType: "uint256", name: "_keyPrice", type: "uint256" },
{
internalType: "uint256",
name: "_maxNumberOfKeys",
type: "uint256",
},
{ internalType: "string", name: "_lockName", type: "string" },
],
name: "initialize",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];
// Create Javascript instances
const lock = web3.eth.contract(LOCK_ABI);
// We connect to the deployed Unlock address see list of addresses on https://docs.unlock-protocol.com/unlock/developers/smart-contracts#unlock
const unlock = web3.eth.contract(UNLOCK_ABI, unlockAddress);
// To create the lock we need to first "compact" its arguments:
const params = lock.methods.initialize(
"address of lock creator", // you would put your address
web3.utils.toBN(2).pow(web3.utils.toBN(256)), // Passing max uint makes these key non expiring
"0x0000000000000000000000000000000000000000", // Currency for these keys is set to use the chain's default currency by passing the 0 address
web3.utils.toBN(0), // Price is 0
web3.utils.toBN(0), // 0 keys are "purchasable" (they will all be granted)
"Proof of engagement for XXX" // name for the contract
);
// Execute the transaction to deploy!
unlock.createUpgradeableLockAtVersion(params, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment