Skip to content

Commit

Permalink
Migrates deploy script from smartweave to AO
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-toth committed Jul 5, 2024
1 parent 8e3b1c5 commit 438b7a6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 50 deletions.
87 changes: 37 additions & 50 deletions deploy.mjs
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))
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"test": "echo \"No tests specified\""
},
"dependencies": {
"@ar.io/sdk": "^1.2.1",
"@iconify-json/eos-icons": "^1.1.10",
"@iconify-json/heroicons": "^1.1.21",
"@iconify-json/heroicons-outline": "^1.1.10",
Expand Down

0 comments on commit 438b7a6

Please sign in to comment.