Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created October 10, 2022 09:07
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 mattdesl/2806575091436e76fbb9013fd76c2692 to your computer and use it in GitHub Desktop.
Save mattdesl/2806575091436e76fbb9013fd76c2692 to your computer and use it in GitHub Desktop.
fetch Meridian locally from the blockchain

Reading Meridian from the Blockchain

You can fetch the Meridian code directly from Ethereum using web3 and a provider of your choice (here I am using Infura, but you might rather use Alchemy or your own local node).

  1. First, copy and paste these files into a new directory.
  2. Run npm install web3 dotenv with a recent version of Node/npm
  3. Create a new .env file with INFURA_API_KEY="YOUR_API_KEY" in it
  4. Run node fetch.js to grab the code, this will save meridian.js
  5. Now you can open index.html and change the tokenData as desired to another hash

A more advanced version of this script would also use the tokenIdToHash method to query the hash of an input mint #801 and then serve a index.html with the correct tokenData.

[
{
"constant": true,
"inputs": [
{ "internalType": "uint256", "name": "_projectId", "type": "uint256" },
{ "internalType": "uint256", "name": "_index", "type": "uint256" }
],
"name": "projectScriptByIndex",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
require("dotenv/config");
const Web3 = require("web3");
const ABI = require("./abi.json");
const fs = require("fs/promises");
const path = require("path");
(async () => {
const network = "mainnet";
const web3 = new Web3(
new Web3.providers.HttpProvider(
`https://${network}.infura.io/v3/${process.env.INFURA_API_KEY}`
)
);
// The ArtBlocks GenArt721Core contract on which Meridian was minted
const contractAddress = "0xa7d8d9ef8d8ce8992df33d8b8cf4aebabd5bd270";
// The project ID for Meridian
const projectId = 163;
const contract = new web3.eth.Contract(ABI, contractAddress);
const result = await contract.methods
.projectScriptByIndex(projectId, 0)
.call({ from: web3.eth.defaultAddress });
console.log("Got result, bytes:", result.length);
await fs.writeFile(path.resolve(__dirname, "meridian.js"), result);
})();
<html>
<head>
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1"
/>
<script>
let tokenData = {
tokenId: "163000801",
hash: "0x4a43c182a8d93c6ba286665ab5dcf77fcb4f79e6a222a78d153304eb463b1edb",
};
</script>
<style type="text/css">
html {
height: 100%;
}
body {
min-height: 100%;
margin: 0;
padding: 0;
}
canvas {
padding: 0;
margin: auto;
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<script src="meridian.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment