Skip to content

Instantly share code, notes, and snippets.

@xiaojay
Created May 23, 2023 04:35
Show Gist options
  • Save xiaojay/a569bea99ee8e391ac198137645e7f32 to your computer and use it in GitHub Desktop.
Save xiaojay/a569bea99ee8e391ac198137645e7f32 to your computer and use it in GitHub Desktop.
import {WarpFactory, defaultCacheOptions, ArweaveGatewayBundledContractDefinitionLoader, ArweaveGatewayBundledInteractionLoader} from 'warp-contracts';
import Arweave from 'arweave';
const arweave = Arweave.init({
host: 'arweave.net',
port: 443,
protocol: 'https',
timeout: 200000
});
const arLoader = new ArweaveGatewayBundledInteractionLoader(arweave, 'mainnet');
const arContractLoader = new ArweaveGatewayBundledContractDefinitionLoader('mainnet');
const contractId = 'TlqASNDLA1Uh8yFiH-BzR_1FDag4s735F3PoUFEv2Mo';
const warp = WarpFactory.custom(
arweave,
{
...defaultCacheOptions,
inMemory: true,
},
'mainnet'
)
.useArweaveGateway()
.setInteractionsLoader(arLoader)
.setDefinitionLoader(arContractLoader)
.build();
const c = warp.contract(contractId).setEvaluationOptions({
allowBigInt: true,
unsafeClient: "skip"
});
async function getState() {
try {
const { sortKey, cachedValue } = await c.readState();
console.log(sortKey, cachedValue.errorMessages, cachedValue.state, cachedValue.validity)
} catch (error) {
console.log('readState error:', error, 'contractId:', contractId);
}
}
getState()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment