Created
May 23, 2023 04:35
-
-
Save xiaojay/a569bea99ee8e391ac198137645e7f32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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