Hi all, I’m trying to use the node sdk to update a simple contract on the testnet.
here’s the parameter struct and function from my contract:
#[derive(Serialize, SchemaType)]
struct SendMessageParameter {
message: String,
}
#[receive(
contract = "factory",
name = "send_message",
parameter = "SendMessageParameter",
mutable
)]
fn send_message<S: HasStateApi>(
ctx: &impl HasReceiveContext,
_host: &mut impl HasHost<State<S>, StateApiType = S>,
) -> ReceiveResult<String> {
let parameter: SendMessageParameter = ctx.parameter_cursor().get()?;
Ok(parameter.message)
}
js client (values filled in for clarity):
const params = serializeUpdateContractParameters(
"factory",
"factory.send_message",
{ message: 'hello world' },
Buffer.from(readFileSync('../contracts/factory/dist/factory/schema.bin'))
)
const tx = {
header: {
expiry: new TransactionExpiry(new Date(Date.now() + 3600000)),
nonce: 164n,
sender: new AccountAddress("3KkSDCzdpXqw7ShVhEGbMbVtp4QScVdazTR8ux5KUNX4ErCXbe"),
},
payload: {
amount: new CcdAmount(0n),
address: { index: BigInt(3222), subindex: BigInt(0) },
receiveName: "factory.send_message",
message: params,
maxContractExecutionEnergy: 300000n
},
type: AccountTransactionType.Update
}
/// sign and send tx....
result:
{
"outcomes": {
"d729b1644742d6e14083a3dced9a275e6f9af760a77acce89a50153f7d89c682": {
"cost": "1878856",
"energyCost": "1009",
"hash": "c0131741396e17060dea3f7c7bb88e208cc37d72a76c48c7f7a9a8a225b26072",
"index": "0",
"result": {
"outcome": "reject",
"rejectReason": {
"contractAddress": {
"index": "3222",
"subindex": 0
},
"parameter": "",
"receiveName": "factory.send_message",
"rejectReason": -2147483646,
"tag": "RejectedReceive"
}
},
"sender": "3KkSDCzdpXqw7ShVhEGbMbVtp4QScVdazTR8ux5KUNX4ErCXbe",
"type": {
"contents": "update",
"type": "accountTransaction"
}
}
},
"status": "finalized"
}
Also, I tried the same logic to update a parameterless contract function and was successful.
any help here would be greatly appreciated. thanks!