Skip to content

Instantly share code, notes, and snippets.

@davebryson
Last active December 1, 2022 15:10
Show Gist options
  • Save davebryson/669a3dbe478ac30b03b9fb81d154e4f2 to your computer and use it in GitHub Desktop.
Save davebryson/669a3dbe478ac30b03b9fb81d154e4f2 to your computer and use it in GitHub Desktop.
/**
* Example code to create an asset and save the meta to arweave
**/
// base token uri
let URL = 'http://localhost:8081/asset/';
// get the chain id from the eth provider. It's needed for the metadata DID
const chainid = provider.getChainId();
// Get the factory
const factory = new ethers.Contract(factoryAddress, factoryabi.abi, signer);
// NOTE: before saving metadata to storage, ensure the caller's wallet is connected
// and they have sufficient balance to pay to create the Asset
// We need the bioasset address to create the metadata. BEFORE we actually create it. Use this
// 'free' call to get the address vs.filtering the tx receipt. Only temporary. Doesn't actually create it
const bioAssetAddress = await factory.callStatic.createAsset("doesn't matter");
// See this helper (may move in the future) to create the asset information from the UI form
// https://github.com/synbionet/synbionet-indexer/blob/main/src/metadata.ts#L56
const meta = createMetaData('...', chainid);
// Save the meta data to storage via the indexer. psuedo code...
const resp = request.post('/asset).send(meta);
if(resp.status == 200) {
const tokenURI = `${URL}/${meta.did}`;
// ... now really create the contract
const tx = await factory.createAsset(tokenURI);
await tx.wait();
}
// contract is deployed...
const basset = new ethers.Contract(assetAddress, bioassetabi.abi, signer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment