-
Notifications
You must be signed in to change notification settings - Fork 1
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 #289 from invariant-labs/replace-code-script
create replace code script
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
Invariant, | ||
Keyring, | ||
Network, | ||
TESTNET_INVARIANT_ADDRESS, | ||
getCodeHash, | ||
initPolkadotApi, | ||
toPercentage | ||
} from '@invariant-labs/a0-sdk' | ||
import dotenv from 'dotenv' | ||
|
||
dotenv.config() | ||
|
||
const main = async () => { | ||
const network = Network.Testnet | ||
const api = await initPolkadotApi(network) | ||
|
||
const keyring = new Keyring({ type: 'sr25519' }) | ||
const mnemonic = process.env.DEPLOYER_MNEMONIC ?? '' | ||
const account = keyring.addFromMnemonic(mnemonic) | ||
console.log(`Deployer: ${account.address}, Mnemonic: ${mnemonic}`) | ||
|
||
const invariant = await Invariant.deploy(api, network, account, toPercentage(1n, 2n), { | ||
storageDepositLimit: 100000000000, | ||
refTime: 100000000000, | ||
proofSize: 100000000000 | ||
}) | ||
console.log(`Invariant: ${invariant.contract.address.toString()}`) | ||
|
||
const codeHash = await getCodeHash(api, invariant.contract.address.toString()) | ||
|
||
const testnetInvariant = await Invariant.load(api, network, TESTNET_INVARIANT_ADDRESS, { | ||
storageDepositLimit: 100000000000, | ||
refTime: 100000000000, | ||
proofSize: 100000000000 | ||
}) | ||
await testnetInvariant.setCode(account, codeHash) | ||
|
||
process.exit(0) | ||
} | ||
|
||
main() |