Bump Contract Code and Data
const SorobanClient = require('soroban-client')
const xdr = SorobanClient.xdr
const pubkey = 'GDK5PG2PVPBL5GV4UFZYXP4QYXBI2Z5FZ5VQTHB7NPYYG3LJI67OAM2X'
const secret = 'SBFUEVT6JTTNFA2ZUDQVGXUAMYHUJIY3AN3C4AGRYVNPOVIEJYFDJ7UV'
const keypair = SorobanClient.Keypair.fromSecret(secret)
const server = new SorobanClient.Server('https://rpc-futurenet.stellar.org')
const contractId = 'CCBBJPFETAFVARNZHXIRDMYZ7EMEZWXIM6WGLTW6QURRABAGNG3OI2XA'
const contract = new SorobanClient.Contract(contractId)
const key = new xdr.ScVal.scvLedgerKeyContractInstance()
const bodyType = xdr.ContractEntryBodyType.dataEntry()
const fee = 10000000;
const contractData = await server.getContractData(contract, key, 'persistent')
const entry = xdr.LedgerEntryData.fromXDR(contractData.xdr, 'base64')
const instance = new xdr.ScContractInstance({ executable: entry.contractData().body().value().val() })
const executable = xdr.ContractExecutable.contractExecutableWasm(instance.executable())
const hash = executable.wasmHash().instance().executable().wasmHash()
const sorobanTransactionData = new xdr.SorobanTransactionData({
resources: new xdr.SorobanResources({
footprint: new xdr.LedgerFootprint({
readOnly: [
xdr.LedgerKey.contractCode(
new xdr.LedgerKeyContractCode({
hash,
bodyType
})
),
xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: contract.address().toScAddress(),
key,
durability: xdr.ContractDataDurability.persistent(),
bodyType
})
)
],
readWrite: []
}),
instructions: 0,
readBytes: 0,
writeBytes: 0,
extendedMetaDataSizeBytes: 0
}),
refundableFee: xdr.Int64.fromString('0'),
ext: new xdr.ExtensionPoint(0)
});
const account = await server.getAccount(pubkey);
const transaction = new SorobanClient.TransactionBuilder(account, {
fee,
networkPassphrase: SorobanClient.Networks.FUTURENET
})
// .addOperation(SorobanClient.Operation.restoreFootprint())
.addOperation(SorobanClient.Operation.bumpFootprintExpiration({
ledgersToExpire: 6312000
}))
.setSorobanData(sorobanTransactionData)
.setTimeout(0)
.build();
preparedTransaction = await server.prepareTransaction(transaction);
preparedTransaction.sign(keypair)
const res = await server.sendTransaction(preparedTransaction);
const resHash = res.hash
console.log(res)
if (res.status === 'ERROR')
return
const interval = setInterval(async () => {
const res = await server.getTransaction(resHash)
if (
res.status === 'SUCCESS'
|| res.status === 'ERROR'
) clearInterval(interval)
console.log(res)
}, 500)
null
no comments