-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from ATOR-Development/46-migrate-ant-deploy-sc…
…ript-from-smartweave-to-ao Migrates deploy script from smartweave to AO
- Loading branch information
Showing
2 changed files
with
38 additions
and
50 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,49 @@ | ||
import Irys from '@irys/sdk'; | ||
import { | ||
LoggerFactory, | ||
WarpFactory, | ||
defaultCacheOptions, | ||
} from 'warp-contracts'; | ||
import Arweave from 'arweave'; | ||
|
||
const ANT = 'kPti-YZrJ86qkGci32Q5inHtbBUlces2mTGTEm_0gzo'; | ||
const DEPLOY_FOLDER = './.output/public'; | ||
const IRYS_NODE = 'https://node2.irys.xyz/'; | ||
import Irys from '@irys/sdk' | ||
import { ANT, ArweaveSigner } from '@ar.io/sdk' | ||
|
||
const processId = '9UpvN6H7sMo0vkuQeou3Ra0pZguWavtpt_8lfqPQlI8' | ||
const DEPLOY_FOLDER = './.output/public' | ||
const IRYS_NODE = 'https://node2.irys.xyz/' | ||
const jwk = JSON.parse( | ||
Buffer.from(process.env.PERMAWEB_KEY || 'NO_KEY', 'base64').toString('utf-8') | ||
); | ||
|
||
LoggerFactory.INST.logLevel('fatal'); | ||
) | ||
const irys = new Irys({ url: IRYS_NODE, token: 'arweave', key: jwk }) | ||
const ant = ANT.init({ | ||
processId, | ||
signer: new ArweaveSigner(jwk) | ||
}) | ||
|
||
let undername = 'dev' | ||
if (process.env.PHASE === 'stage') { | ||
undername = 'stage' | ||
} else if (process.env.PHASE === 'live') { | ||
undername = '@' | ||
} | ||
|
||
const irys = new Irys({ url: IRYS_NODE, token: 'arweave', key: jwk }); | ||
async function deploy() { | ||
const buildArtifact = await irys.uploadFolder(DEPLOY_FOLDER, { | ||
indexFile: 'index.html' | ||
}) | ||
|
||
// upload folder | ||
const result = await irys.uploadFolder(DEPLOY_FOLDER, { | ||
indexFile: 'index.html', | ||
}); | ||
if (!buildArtifact) { | ||
console.error('Irys result error', buildArtifact) | ||
|
||
// update ANT | ||
if (result) { | ||
console.log('irys result id', result.id); | ||
var subDomain = 'dev'; | ||
if (process.env.PHASE === 'live') { | ||
subDomain = '@'; | ||
} else if (process.env.PHASE === 'stage') { | ||
subDomain = 'stage'; | ||
return | ||
} | ||
|
||
console.log(`Deploying to: ${subDomain}`); | ||
|
||
const arweave = Arweave.init({ | ||
host: 'arweave.net', | ||
port: 443, | ||
protocol: 'https', | ||
}); | ||
console.log('Irys result id', buildArtifact.id) | ||
console.log('Updating ANT undername', undername) | ||
|
||
const warp = WarpFactory.custom(arweave, defaultCacheOptions, 'mainnet') | ||
.useArweaveGateway() | ||
.build(); | ||
const contract = warp.contract(ANT).connect(jwk); | ||
|
||
const deployed = await contract.writeInteraction({ | ||
function: 'setRecord', | ||
subDomain: subDomain, | ||
ttlSeconds: 3600, | ||
transactionId: result.id, | ||
}); | ||
const { id: deployedTxId } = await ant.setRecord({ | ||
undername, | ||
transactionId: buildArtifact.id, | ||
ttlSeconds: 3600 | ||
}) | ||
|
||
console.log( | ||
'Deployed! Please wait 20 - 30 minutes for ArNS to update!', | ||
deployed | ||
); | ||
} else { | ||
console.error('Irys result error', result); | ||
'Deployed! Please wait 20 - 30 minutes for ARNS to update!', | ||
deployedTxId | ||
) | ||
} | ||
|
||
deploy().then().catch(err => console.error(err)) |
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