Skip to content

Instantly share code, notes, and snippets.

@kopanitsa
Created March 2, 2018 12:16
Show Gist options
  • Save kopanitsa/78efb9204e6dbfed0121f063b0e228c1 to your computer and use it in GitHub Desktop.
Save kopanitsa/78efb9204e6dbfed0121f063b0e228c1 to your computer and use it in GitHub Desktop.
// Generate contract instance. Pass contract address as 2nd parameter.
Contract contract(&web3, CONTRACT_ADDRESS);
// Set your secret to contract.
// This secret will not send to server (of course!) but use in local to sign.
contract.SetPrivateKey((uint8_t*)PRIVATE_KEY);
// set required data to execute sendTransaction
// nonce can be get with web3.EthGetTransactionCount() API
uint32_t nonceVal = (uint32_t)web3.EthGetTransactionCount((char *)MY_ADDRESS);
uint32_t gasPriceVal = 141006540;
uint32_t gasLimitVal = 3000000;
uint8_t toStr[] = CONTRACT_ADDRESS;
uint8_t valueStr[] = "0x00";
uint8_t dataStr[100];
memset(dataStr, 0, 100);
// Generate binary data to send contract.
// In this case, generate data to send to "set(uint256)" and use "123" as first parameter.
contract.SetupContractData((char*)dataStr, "set(uint256)", 123);
// send transaction
contract.SendTransaction((uint8_t *) result,
nonceVal, gasPriceVal, gasLimitVal, toStr, valueStr, dataStr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment