product's notebooks

  • Generate Mutation for the Creation of an Asset - /product/generate-mutation-for-the-creation-of-an-asset
    Last edited 10 months ago
    /* eslint-disable no-console */ /* eslint-disable camelcase */ /* CREATES AN ASSET Properties for asset shall follow the standard https://docs.livingassets.io/api/props_standard/ INPUTS: * pvk: the private key of the owner of the universe * owner: the id of the owner to whom the asset will be assigned * uni: the universe id * nonce: the Number used ONly onCE of the owner to whom the asset will be assigned, * (see the get_user_nonce.js example) * asset_props: the attributes of the asset * asset_metadata: attributes of the asset that will not be certified by the blockchain */ const pvk = '0xd2827f4c3778758eb51719a698464aaffd10a5c7cf816c1de83c5e446bfc8e8d'; const owner = '0x983c1A8FCf74CAF648fD51fd7A6d322a502ae789'; const uni = '0'; const nonce = '0'; const asset_props = { name: 'Supercool Dragon', description: 'Legendary creature that loves fire.', image: 'ipfs://QmPCHHeL1i6ZCUnQ1RdvQ5G3qccsjgQF8GkJrWAm54kdtB', animation_url: 'ipfs://QmefzYXCtUXudCy9LYjU4biapHJiP26EGYS8hQjpei472j', attributes: [ { trait_type: 'Rarity', value: 'Scarce', }, { trait_type: 'Level', value: 5, }, { trait_type: 'Weight', value: 123.5, }, ], }; const asset_metadata = { private_data: 'that only I will see', }; // CREATING THE ASSET: require("utf-8-validate"); const identity = require('freeverse-crypto-js'); const { createAssetOp, AtomicAssetOps } = require("freeverse-apisigner-js"); // create web3 account from your private key // (other forms of creating web3 account could be substituted) const universe_owner_account = identity.accountFromPrivateKey(pvk); // instantiate the class to create the required mutation: const assetOps = new AtomicAssetOps({ universeId: uni }); const op = createAssetOp({ nonce, ownerId: owner, props: asset_props, metadata: asset_metadata, }); assetOps.push({ op }); const sig = assetOps.sign({ web3Account: universe_owner_account }); const mutation = assetOps.mutation({ signature: sig }); ` --------------- Mutation to be sent to GraphQL endpoint: ${mutation} `
  • Generate Public Private Keypair - /product/generate-public-private-keypair
    Last edited 10 months ago
    // It generates a random Public and Private keypair everytime it runs const Wallet = require('ethereumjs-wallet'); const EthWallet = Wallet.default.generate(); ` Generated ID: - privateKey : ${EthWallet.getPrivateKeyString().slice(2)} - publicKey : ${EthWallet.getPublicKeyString().slice(2)} - web3 address : ${EthWallet.getAddressString()} `
  • Generate Identity - /product/generate-identity
    Last edited 10 months ago
    /* eslint-disable no-console */ /* Generates a brand new identity and encrypts it with a provided user password Use at your own risk. The generated privKey will be output in console. INPUTS: - password: the password that will be used to encrypt */ const password = 'your_password'; // Generating: require("utf-8-validate"); const identity = require('freeverse-crypto-js'); const newId = identity.createNewAccount(); const encrypted = identity.encryptIdentity(newId.privateKey, password); ` Generated ID: - privateKey : ${newId.privateKey} - web3 address : ${newId.address} - encryptedId : ${encrypted} - userPassword : ${password} `
  • Update Image - /product/update-image
    Last edited a year ago
    // Disclaimer: This snippet runs on a shared environment. Execution times will vary // Replace with an actual private key const pvk = '0xd2827f4c3778758eb51719a698464aaffd10a5c7cf816c1de83c5e446bfc1111'; const asset = '1858476204501659870681251187806966130514471238263'; const uni = '0'; const nonce = '0'; const updated_asset_props = { image: 'ipfs://QmPCHHeL1i6ZCUnQ1RdvQ5G3qccsjgQF8GkJrWAm54kdtB', }; require("utf-8-validate") const identity = require('freeverse-crypto-js'); const { updateAssetOp, AtomicAssetOps } = require('freeverse-apisigner-js'); // create web3 account from your private key // (other forms of creating web3 account could be subsituted) const universe_owner_account = identity.accountFromPrivateKey(pvk); // instantiate the class to create the required mutation: const assetOps = new AtomicAssetOps({ universeId: uni }); const op = updateAssetOp({ nonce, assetId: asset, props: updated_asset_props, metadata: null, }); assetOps.push({ op }); const sig = assetOps.sign({ web3Account: universe_owner_account }); const mutation = assetOps.mutation({ signature: sig }); ` Mutation to be sent to GraphQL endpoint: ${mutation} `
  • Base64 encoded text - /product/base64-encoded-text
    Last edited a year ago
    const input = 'http://redirected.url'; const base64data = new Buffer.from(input).toString('base64'); console.log(input + ' converted to Base64 is ' + base64data); process.exit();
  • Get MH Assets - /product/get-mh-assets
    Last edited a year ago
    /* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable no-await-in-loop */ /* eslint-disable no-console */ const fetch = require('isomorphic-fetch'); async function getAssetsCount(universeId) { const getAssetsCountQuery = ` query($universeId: Int!) { allAssets(condition: {universeId:$universeId} ) { totalCount } } `; const response = await fetch(process.env.PROD_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query: getAssetsCountQuery, variables: { universeId, }, }), }); const result = await response.json(); const data = result.data.allAssets; return data === null ? 0 : data.totalCount; } const run = async () => { const count = await getAssetsCount(parseInt(process.env.MH_UNIVERSE_ID)); console.log(`#assets in MH: ${count}`); }; run();